mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +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
|
||||
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
|
||||
NSDictionary *responseJSON;
|
||||
NSArray *responseJSON;
|
||||
if (connectionError == nil) {
|
||||
NSStringEncoding encoding = NSUTF8StringEncoding;
|
||||
if (response.textEncodingName) {
|
||||
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)response.textEncodingName);
|
||||
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
|
||||
}
|
||||
NSHTTPURLResponse *httpResponse = nil;
|
||||
if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
|
||||
// Might be a local file request
|
||||
httpResponse = (NSHTTPURLResponse *)response;
|
||||
}
|
||||
responseJSON = @{
|
||||
@"status": @([httpResponse statusCode] ?: 200),
|
||||
@"responseHeaders": [httpResponse allHeaderFields] ?: @{},
|
||||
@"responseText": [[NSString alloc] initWithData:data encoding:encoding] ?: @""
|
||||
};
|
||||
responseJSON = @[
|
||||
@(httpResponse.statusCode ?: 200),
|
||||
httpResponse.allHeaderFields ?: @{},
|
||||
[[NSString alloc] initWithData:data encoding:encoding] ?: @"",
|
||||
];
|
||||
} else {
|
||||
responseJSON = @{
|
||||
@"status": @0,
|
||||
@"responseHeaders": @{},
|
||||
@"responseText": [connectionError localizedDescription] ?: [NSNull null]
|
||||
};
|
||||
responseJSON = @[
|
||||
@(httpResponse.statusCode),
|
||||
httpResponse.allHeaderFields ?: @{},
|
||||
connectionError.localizedDescription ?: [NSNull null],
|
||||
];
|
||||
}
|
||||
|
||||
// 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?
|
||||
'h' + crc32(method + '|' + url + '|' + data),
|
||||
(result) => {
|
||||
result = JSON.parse(result);
|
||||
this.callback(result.status, result.responseHeaders, result.responseText);
|
||||
}
|
||||
this.callback.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user