Нема описа

OSSAllRequestNeededMessage.m 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // OSSAllRequestNeededMessage.m
  3. // AliyunOSSSDK
  4. //
  5. // Created by huaixu on 2018/1/22.
  6. // Copyright © 2018年 aliyun. All rights reserved.
  7. //
  8. #import "OSSAllRequestNeededMessage.h"
  9. #import "OSSDefine.h"
  10. #import "OSSUtil.h"
  11. @implementation OSSAllRequestNeededMessage
  12. - (instancetype)initWithEndpoint:(NSString *)endpoint
  13. httpMethod:(NSString *)httpMethod
  14. bucketName:(NSString *)bucketName
  15. objectKey:(NSString *)objectKey
  16. type:(NSString *)contentType
  17. md5:(NSString *)contentMd5
  18. range:(NSString *)range
  19. date:(NSString *)date
  20. headerParams:(NSMutableDictionary *)headerParams
  21. querys:(NSMutableDictionary *)querys {
  22. if (self = [super init]) {
  23. _endpoint = endpoint;
  24. _httpMethod = httpMethod;
  25. _bucketName = bucketName;
  26. _objectKey = objectKey;
  27. _contentType = contentType;
  28. _contentMd5 = contentMd5;
  29. _range = range;
  30. _date = date;
  31. _headerParams = headerParams;
  32. if (!_headerParams) {
  33. _headerParams = [NSMutableDictionary new];
  34. }
  35. _querys = querys;
  36. if (!_querys) {
  37. _querys = [NSMutableDictionary new];
  38. }
  39. }
  40. return self;
  41. }
  42. - (instancetype)initWithEndpoint:(NSString *)endpoint
  43. httpMethod:(NSString *)httpMethod
  44. bucketName:(NSString *)bucketName
  45. objectKey:(NSString *)objectKey
  46. type:(NSString *)contentType
  47. md5:(NSString *)contentMd5
  48. range:(NSString *)range
  49. date:(NSString *)date
  50. headerParams:(NSMutableDictionary *)headerParams
  51. querys:(NSMutableDictionary *)querys
  52. sha1:(NSString *)contentSHA1
  53. {
  54. if (self = [super init])
  55. {
  56. _endpoint = endpoint;
  57. _httpMethod = httpMethod;
  58. _bucketName = bucketName;
  59. _objectKey = objectKey;
  60. _contentType = contentType;
  61. _contentMd5 = contentMd5;
  62. _range = range;
  63. _date = date;
  64. _contentSHA1 = contentSHA1;
  65. _headerParams = headerParams;
  66. if (!_headerParams) {
  67. _headerParams = [NSMutableDictionary new];
  68. }
  69. _querys = querys;
  70. if (!_querys) {
  71. _querys = [NSMutableDictionary new];
  72. }
  73. }
  74. return self;
  75. }
  76. - (OSSTask *)validateRequestParamsInOperationType:(OSSOperationType)operType {
  77. NSString * errorMessage = nil;
  78. if (!self.endpoint) {
  79. errorMessage = @"Endpoint should not be nil";
  80. }
  81. if (!self.bucketName && operType != OSSOperationTypeGetService) {
  82. errorMessage = @"Bucket name should not be nil";
  83. }
  84. if (self.bucketName && ![OSSUtil validateBucketName:self.bucketName]) {
  85. errorMessage = @"Bucket name invalid";
  86. }
  87. if (!self.objectKey &&
  88. (operType != OSSOperationTypeGetBucket && operType != OSSOperationTypeCreateBucket
  89. && operType != OSSOperationTypeDeleteBucket && operType != OSSOperationTypeGetService
  90. && operType != OSSOperationTypeGetBucketACL&& operType != OSSOperationTypeDeleteMultipleObjects
  91. && operType != OSSOperationTypeListMultipartUploads)) {
  92. errorMessage = @"Object key should not be nil";
  93. }
  94. if (self.objectKey && ![OSSUtil validateObjectKey:self.objectKey]) {
  95. errorMessage = @"Object key invalid";
  96. }
  97. if (errorMessage) {
  98. return [OSSTask taskWithError:[NSError errorWithDomain:OSSClientErrorDomain
  99. code:OSSClientErrorCodeInvalidArgument
  100. userInfo:@{OSSErrorMessageTOKEN: errorMessage}]];
  101. } else {
  102. return [OSSTask taskWithResult:nil];
  103. }
  104. }
  105. - (NSString *)description
  106. {
  107. 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];
  108. }
  109. @end