Files
flipper/iOS/Plugins/FlipperKitNetworkPlugin/FlipperKitNetworkPlugin/SKResponseInfo.m
Pascal Hartig bbee7a3357 Update iOS license headers (and more)
Summary: Add the affiliates bit that the linter is checking for.

Reviewed By: jknoxville

Differential Revision: D15164826

fbshipit-source-id: 500ffe89ec0c2fd3acfbc374408d16a337cecfa4
2019-05-02 03:28:07 -07:00

44 lines
1.4 KiB
Objective-C

/*
* Copyright (c) 2018-present, 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