Fix "urlencoded" HTTP header notation

Misspelling caused data to be sent as binary (browser default?)
rather than urlencoded, meaning it doesn't show up in $_POST.
This commit is contained in:
Ingo Schommer 2016-04-18 08:45:59 +12:00 committed by Damian Mooyman
parent 28e81db545
commit 90e352ca7d
2 changed files with 8 additions and 8 deletions

View File

@ -59,7 +59,7 @@ class SilverStripeBackend {
* Both `payloadFormat` and `responseFormat` can use the following shortcuts for their
* corresponding mime types:
*
* - urlencoded: application/x-www-form-url-encoded
* - urlencoded: application/x-www-form-urlencoded
* - json: application/json
*
* Requests with `method: 'get'` will automatically be sent as `urlencoded`,
@ -109,7 +109,7 @@ class SilverStripeBackend {
*/
function encode(contentType, data) {
switch (contentType) {
case 'application/x-www-form-url-encoded':
case 'application/x-www-form-urlencoded':
return qs.stringify(data);
case 'application/json':
@ -134,7 +134,7 @@ class SilverStripeBackend {
*/
function decode(contentType, text) {
switch (contentType) {
case 'application/x-www-form-url-encoded':
case 'application/x-www-form-urlencoded':
return qs.parse(text);
case 'application/json':
@ -238,7 +238,7 @@ class SilverStripeBackend {
newUrl = addQuerystring(
newUrl,
encode('application/x-www-form-url-encoded', queryData)
encode('application/x-www-form-urlencoded', queryData)
);
// Template placeholders
@ -257,7 +257,7 @@ class SilverStripeBackend {
// Parameter defaults
const refinedSpec = Object.assign({
method: 'get',
payloadFormat: 'application/x-www-form-url-encoded',
payloadFormat: 'application/x-www-form-urlencoded',
responseFormat: 'application/json',
payloadSchema: {},
defaultData: {},
@ -266,7 +266,7 @@ class SilverStripeBackend {
// Substitute shorcut format values with their full mime types
const formatShortcuts = {
json: 'application/json',
urlencoded: 'application/x-www-form-url-encoded',
urlencoded: 'application/x-www-form-urlencoded',
};
['payloadFormat', 'responseFormat'].forEach(
(key) => {

View File

@ -146,7 +146,7 @@ describe('SilverStripeBackend', () => {
expect(mock.get.mock.calls[0][0]).toEqual('http://example.org?id=1&values%5Ba%5D=aye&values%5Bb%5D=bee');
expect(mock.get.mock.calls[0][1]).toEqual({
Accept: 'application/json',
'Content-Type': 'application/x-www-form-url-encoded',
'Content-Type': 'application/x-www-form-urlencoded',
});
});
@ -251,7 +251,7 @@ describe('SilverStripeBackend', () => {
expect(mock.get.mock.calls[0][0]).toEqual('http://example.com/1/2/?foo=bar&two=2&three=3');
expect(mock.get.mock.calls[0][1]).toEqual({
Accept: 'application/json',
'Content-Type': 'application/x-www-form-url-encoded',
'Content-Type': 'application/x-www-form-urlencoded',
});
});