Fix null values in network requests

This commit is contained in:
Nick Lockwood 2015-08-14 05:13:40 -07:00
parent 96277ca3f5
commit 3f5fcadbd5
2 changed files with 5 additions and 6 deletions

View File

@ -140,12 +140,12 @@ RCT_EXPORT_MODULE()
- (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query
completionBlock:(void (^)(NSURLRequest *request))block completionBlock:(void (^)(NSURLRequest *request))block
{ {
NSURL *URL = [RCTConvert NSURL:query[@"url"]]; NSURL *URL = [RCTConvert NSURL:query[@"url"]]; // this is marked as nullable in JS, but should not be null
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = [[RCTConvert NSString:query[@"method"]] uppercaseString] ?: @"GET"; request.HTTPMethod = [[RCTConvert NSString:RCTNilIfNull(query[@"method"])] uppercaseString] ?: @"GET";
request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]]; request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]];
NSDictionary *data = [RCTConvert NSDictionary:query[@"data"]]; NSDictionary *data = [RCTConvert NSDictionary:RCTNilIfNull(query[@"data"])];
return [self processDataForHTTPQuery:data callback:^(NSError *error, NSDictionary *result) { return [self processDataForHTTPQuery:data callback:^(NSError *error, NSDictionary *result) {
if (error) { if (error) {
RCTLogError(@"Error processing request body: %@", error); RCTLogError(@"Error processing request body: %@", error);
@ -220,7 +220,7 @@ RCT_EXPORT_MODULE()
* - @"contentType" (NSString): the content type header of the request * - @"contentType" (NSString): the content type header of the request
* *
*/ */
- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(NSDictionary *)query callback: - (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(nullable NSDictionary *)query callback:
(RCTURLRequestCancellationBlock (^)(NSError *error, NSDictionary *result))callback (RCTURLRequestCancellationBlock (^)(NSError *error, NSDictionary *result))callback
{ {
if (!query) { if (!query) {

View File

@ -104,8 +104,7 @@ class XMLHttpRequest extends XMLHttpRequestBase {
sendImpl(method: ?string, url: ?string, headers: Object, data: any): void { sendImpl(method: ?string, url: ?string, headers: Object, data: any): void {
if (typeof data === 'string') { if (typeof data === 'string') {
data = {string: data}; data = {string: data};
} } else if (data instanceof FormData) {
if (data instanceof FormData) {
data = {formData: data.getParts()}; data = {formData: data.getParts()};
} }
RCTNetworking.sendRequest( RCTNetworking.sendRequest(