Reviewed By: scottrice Differential Revision: D17673481 fbshipit-source-id: 1794e0a6e92e6894b5634b24c6e7910847616261
42 lines
1.3 KiB
Objective-C
42 lines
1.3 KiB
Objective-C
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the LICENSE
|
|
* file in the root directory of this source tree.
|
|
*/
|
|
#import "SKResponseInfo.h"
|
|
|
|
@implementation SKResponseInfo
|
|
@synthesize identifier = _identifier;
|
|
@synthesize timestamp = _timestamp;
|
|
@synthesize response = _response;
|
|
@synthesize body = _body;
|
|
|
|
- (instancetype)initWithIndentifier:(int64_t)identifier timestamp:(uint64_t)timestamp response:(NSURLResponse *)response data:(NSData *)data {
|
|
if(self = [super init]) {
|
|
_identifier = identifier;
|
|
_timestamp = timestamp;
|
|
_response = response;
|
|
_body = [SKResponseInfo shouldStripReponseBodyWithResponse:response] ? nil : [data base64EncodedStringWithOptions: 0];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
+ (BOOL) shouldStripReponseBodyWithResponse:(NSURLResponse *)response {
|
|
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response;
|
|
NSString *contentType = httpResponse.allHeaderFields[@"content-type"];
|
|
if (!contentType) {
|
|
return NO;
|
|
}
|
|
|
|
return [contentType containsString:@"image/"] ||
|
|
[contentType containsString:@"video/"] ||
|
|
[contentType containsString:@"application/zip"];
|
|
}
|
|
|
|
- (void)setBodyFromData:(NSData *_Nullable)data {
|
|
self.body = [SKResponseInfo shouldStripReponseBodyWithResponse:self.response] ? nil : [data base64EncodedStringWithOptions: 0];
|
|
}
|
|
|
|
@end
|