mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 23:28:12 +00:00
Removed redundant JSON encode/decode from RCTDataManager
Summary: @public For some reason we were manually JSON-encoding the RCTDataManager responses, and then decoding them again on the JS side. Since all data sent over the bridge is JSON-encoded anyway, this is pretty pointless. Test Plan: * Test Movies app in OSS, which uses RCTDataManager * Test any code that uses RKHTTPQueryGenericExecutor to make network requests (e.g. Groups) * Test the Groups photo upload feature, which uses RKHTTPQueryWithImageUploadExecutor
This commit is contained in:
parent
b03446e27e
commit
a2db4a4a5b
@ -39,34 +39,35 @@ RCT_EXPORT_METHOD(queryData:(NSString *)queryType
|
|||||||
// Build data task
|
// Build data task
|
||||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {
|
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *connectionError) {
|
||||||
|
|
||||||
|
NSHTTPURLResponse *httpResponse = nil;
|
||||||
|
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
|
||||||
|
// Might be a local file request
|
||||||
|
httpResponse = (NSHTTPURLResponse *)response;
|
||||||
|
}
|
||||||
|
|
||||||
// Build response
|
// Build response
|
||||||
NSDictionary *responseJSON;
|
NSArray *responseJSON;
|
||||||
if (connectionError == nil) {
|
if (connectionError == nil) {
|
||||||
NSStringEncoding encoding = NSUTF8StringEncoding;
|
NSStringEncoding encoding = NSUTF8StringEncoding;
|
||||||
if (response.textEncodingName) {
|
if (response.textEncodingName) {
|
||||||
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName);
|
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName);
|
||||||
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
|
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
|
||||||
}
|
}
|
||||||
NSHTTPURLResponse *httpResponse = nil;
|
responseJSON = @[
|
||||||
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
|
@(httpResponse.statusCode ?: 200),
|
||||||
// Might be a local file request
|
httpResponse.allHeaderFields ?: @{},
|
||||||
httpResponse = (NSHTTPURLResponse *)response;
|
[[NSString alloc] initWithData:data encoding:encoding] ?: @"",
|
||||||
}
|
];
|
||||||
responseJSON = @{
|
|
||||||
@"status": @([httpResponse statusCode] ?: 200),
|
|
||||||
@"responseHeaders": [httpResponse allHeaderFields] ?: @{},
|
|
||||||
@"responseText": [[NSString alloc] initWithData:data encoding:encoding] ?: @""
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
responseJSON = @{
|
responseJSON = @[
|
||||||
@"status": @0,
|
@(httpResponse.statusCode),
|
||||||
@"responseHeaders": @{},
|
httpResponse.allHeaderFields ?: @{},
|
||||||
@"responseText": [connectionError localizedDescription] ?: [NSNull null]
|
connectionError.localizedDescription ?: [NSNull null],
|
||||||
};
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send response (won't be sent on same thread as caller)
|
// Send response (won't be sent on same thread as caller)
|
||||||
responseSender(@[RCTJSONStringify(responseJSON, NULL)]);
|
responseSender(responseJSON);
|
||||||
|
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
@ -30,10 +30,7 @@ class XMLHttpRequest extends XMLHttpRequestBase {
|
|||||||
},
|
},
|
||||||
// TODO: Do we need this? is it used anywhere?
|
// TODO: Do we need this? is it used anywhere?
|
||||||
'h' + crc32(method + '|' + url + '|' + data),
|
'h' + crc32(method + '|' + url + '|' + data),
|
||||||
(result) => {
|
this.callback.bind(this)
|
||||||
result = JSON.parse(result);
|
|
||||||
this.callback(result.status, result.responseHeaders, result.responseText);
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user