1515#import " NSString+QCloudSHA.h"
1616#import < CommonCrypto/CommonDigest.h>
1717#import " QCloudLogger.h"
18+
19+ @implementation NSDictionary (HeaderFilter)
20+ - (NSDictionary *)filteHeaders ; {
21+ NSMutableDictionary * signedHeaders = [[NSMutableDictionary alloc ] init ];
22+ __block const NSArray * shouldSignedHeaderList = @[ @" Content-Length" , @" Content-MD5" ,@" Host" ];
23+ [self enumerateKeysAndObjectsUsingBlock: ^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
24+ // 签名的Headers列表:x开头的(x-cos-之类的),host,content-length,content-MD5
25+ BOOL shouldSigned = NO ;
26+ for (NSString * header in shouldSignedHeaderList) {
27+ if ([header isEqualToString: ((NSString *)key)]) {
28+ shouldSigned = YES ;
29+ }
30+ }
31+ NSArray * headerSeperatedArray = [key componentsSeparatedByString: @" -" ];
32+ if ([headerSeperatedArray firstObject ] && [headerSeperatedArray.firstObject isEqualToString: @" x" ]) {
33+ shouldSigned = YES ;
34+ }
35+ if (shouldSigned) {
36+ signedHeaders[key]=obj;
37+ }
38+ }];
39+ return [signedHeaders copy ];
40+ }
41+ @end
42+
43+
44+
1845@implementation QCloudAuthentationV5Creator
1946
2047- (QCloudSignature*) signatureForData : (NSMutableURLRequest *)urlrequest
@@ -35,8 +62,7 @@ - (QCloudSignature*) signatureForData:(NSMutableURLRequest *)urlrequest
3562 }
3663 NSString * signTime = [NSString stringWithFormat: @" %lld ;%lld " ,(int64_t )nowInterval, (int64_t )experationInterVal];
3764 //
38- NSDictionary * headers = [urlrequest allHTTPHeaderFields ];
39-
65+ NSDictionary * headers = [[urlrequest allHTTPHeaderFields ] filteHeaders ];
4066 NSDictionary * urlParamters = QCloudURLReadQuery (urlrequest.URL );
4167 NSDictionary * (^LowcaseDictionary)(NSDictionary * origin) = ^(NSDictionary * origin) {
4268 NSMutableDictionary * aim = [NSMutableDictionary new ];
@@ -114,4 +140,6 @@ - (QCloudSignature*) signatureForData:(NSMutableURLRequest *)urlrequest
114140 QCloudLogDebug (@" authoration is %@ " , authoration);
115141 return [QCloudSignature signatureWith1Day: authoration];
116142}
143+
144+
117145@end
0 commit comments