From 4450d789e0760c294d885052c38ffa00e26a7554 Mon Sep 17 00:00:00 2001 From: Dave Sibiski Date: Wed, 13 Apr 2016 06:47:29 -0700 Subject: [PATCH] Uppercases the `method` variable to sanitize the string Summary:This prevents possible developer errors when using 'post' or 'put' instead of 'POST' and 'PUT'. Fixes: https://github.com/facebook/react-native/issues/6855 **Test plan:** Previously, a `method put must not have a request body` error would be thrown when the method was in lowercase and a request body was indeed included. With this fix and the following code (note the method name in all lowercase), the request is properly completed. ```javascript const url = 'http://myurl.com'; const request = new XMLHttpRequest(); request.open('put', url); request.setRequestHeader("Content-type","application/json"); request.onload = function() { console.log('onload'); }; request.onerror = function() { console.log('error'); }; request.send(JSON.stringify({ something: 'here' })); ``` Closes https://github.com/facebook/react-native/pull/6956 Differential Revision: D3173467 Pulled By: davidaurelio fb-gh-sync-id: add90e9f31cd4f548547a3f85267a782ae74a89c fbshipit-source-id: add90e9f31cd4f548547a3f85267a782ae74a89c --- Libraries/Network/XMLHttpRequestBase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Network/XMLHttpRequestBase.js b/Libraries/Network/XMLHttpRequestBase.js index 972a4db73..784e00668 100644 --- a/Libraries/Network/XMLHttpRequestBase.js +++ b/Libraries/Network/XMLHttpRequestBase.js @@ -304,7 +304,7 @@ class XMLHttpRequestBase { throw new Error('Cannot load an empty url'); } this._reset(); - this._method = method; + this._method = method.toUpperCase(); this._url = url; this._aborted = false; this.setReadyState(this.OPENED);