123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- //
- // OSSAllRequestNeededMessage.m
- // AliyunOSSSDK
- //
- // Created by huaixu on 2018/1/22.
- // Copyright © 2018年 aliyun. All rights reserved.
- //
-
- #import "OSSAllRequestNeededMessage.h"
-
- #import "OSSDefine.h"
- #import "OSSUtil.h"
-
- @implementation OSSAllRequestNeededMessage
-
- - (instancetype)initWithEndpoint:(NSString *)endpoint
- httpMethod:(NSString *)httpMethod
- bucketName:(NSString *)bucketName
- objectKey:(NSString *)objectKey
- type:(NSString *)contentType
- md5:(NSString *)contentMd5
- range:(NSString *)range
- date:(NSString *)date
- headerParams:(NSMutableDictionary *)headerParams
- querys:(NSMutableDictionary *)querys {
-
- if (self = [super init]) {
- _endpoint = endpoint;
- _httpMethod = httpMethod;
- _bucketName = bucketName;
- _objectKey = objectKey;
- _contentType = contentType;
- _contentMd5 = contentMd5;
- _range = range;
- _date = date;
- _headerParams = headerParams;
- if (!_headerParams) {
- _headerParams = [NSMutableDictionary new];
- }
- _querys = querys;
- if (!_querys) {
- _querys = [NSMutableDictionary new];
- }
- }
- return self;
- }
-
- - (instancetype)initWithEndpoint:(NSString *)endpoint
- httpMethod:(NSString *)httpMethod
- bucketName:(NSString *)bucketName
- objectKey:(NSString *)objectKey
- type:(NSString *)contentType
- md5:(NSString *)contentMd5
- range:(NSString *)range
- date:(NSString *)date
- headerParams:(NSMutableDictionary *)headerParams
- querys:(NSMutableDictionary *)querys
- sha1:(NSString *)contentSHA1
- {
- if (self = [super init])
- {
- _endpoint = endpoint;
- _httpMethod = httpMethod;
- _bucketName = bucketName;
- _objectKey = objectKey;
- _contentType = contentType;
- _contentMd5 = contentMd5;
- _range = range;
- _date = date;
- _contentSHA1 = contentSHA1;
- _headerParams = headerParams;
- if (!_headerParams) {
- _headerParams = [NSMutableDictionary new];
- }
- _querys = querys;
- if (!_querys) {
- _querys = [NSMutableDictionary new];
- }
- }
- return self;
- }
-
- - (OSSTask *)validateRequestParamsInOperationType:(OSSOperationType)operType {
- NSString * errorMessage = nil;
-
- if (!self.endpoint) {
- errorMessage = @"Endpoint should not be nil";
- }
-
- if (!self.bucketName && operType != OSSOperationTypeGetService) {
- errorMessage = @"Bucket name should not be nil";
- }
-
- if (self.bucketName && ![OSSUtil validateBucketName:self.bucketName]) {
- errorMessage = @"Bucket name invalid";
- }
-
- if (!self.objectKey &&
- (operType != OSSOperationTypeGetBucket && operType != OSSOperationTypeCreateBucket
- && operType != OSSOperationTypeDeleteBucket && operType != OSSOperationTypeGetService
- && operType != OSSOperationTypeGetBucketACL&& operType != OSSOperationTypeDeleteMultipleObjects
- && operType != OSSOperationTypeListMultipartUploads)) {
- errorMessage = @"Object key should not be nil";
- }
-
-
-
- if (self.objectKey && ![OSSUtil validateObjectKey:self.objectKey]) {
- errorMessage = @"Object key invalid";
- }
-
- if (errorMessage) {
- return [OSSTask taskWithError:[NSError errorWithDomain:OSSClientErrorDomain
- code:OSSClientErrorCodeInvalidArgument
- userInfo:@{OSSErrorMessageTOKEN: errorMessage}]];
- } else {
- return [OSSTask taskWithResult:nil];
- }
- }
-
- - (NSString *)description
- {
- return [NSString stringWithFormat:@"<OSSAllRequestNeededMessage: %p>{endpoint: %@\nhttpMethod: %@\nbucketName: %@\nobjectKey: %@\ncontentType: %@\ncontentMd5: %@\nrange: %@\ndate: %@\nheaderParams: %@\nquerys: %@\ncontentSHA1: %@\nisHostInCnameExcludeList: %d\n}",self, _endpoint, _httpMethod, _bucketName, _objectKey, _contentType, _contentMd5, _range, _date, _headerParams, _querys, _contentSHA1, _isHostInCnameExcludeList];
- }
-
- @end
|