File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -161,13 +161,13 @@ describe("httpRequest", () => {
161
161
} )
162
162
} ) ;
163
163
164
- it ( "should encode a JSON body by default" , ( done ) => {
164
+ it ( "should encode a query string body by default" , ( done ) => {
165
165
let options = {
166
166
body : { "foo" : "bar" } ,
167
167
}
168
168
let result = httpRequest . encodeBody ( options ) ;
169
- expect ( result . body ) . toEqual ( '{" foo":" bar"} ' ) ;
170
- expect ( result . headers [ 'Content-Type' ] ) . toEqual ( 'application/json ' ) ;
169
+ expect ( result . body ) . toEqual ( 'foo= bar' ) ;
170
+ expect ( result . headers [ 'Content-Type' ] ) . toEqual ( 'application/x-www-form-urlencoded ' ) ;
171
171
done ( ) ;
172
172
173
173
} )
Original file line number Diff line number Diff line change @@ -13,12 +13,10 @@ var encodeBody = function({body, headers = {}}) {
13
13
14
14
if ( contentTypeKeys . length == 0 ) {
15
15
// no content type
16
- try {
17
- body = JSON . stringify ( body ) ;
18
- headers [ 'Content-Type' ] = 'application/json' ;
19
- } catch ( e ) {
20
- // do nothing;
21
- }
16
+ // As per https://parse.com/docs/cloudcode/guide#cloud-code-advanced-sending-a-post-request the default encoding is supposedly x-www-form-urlencoded
17
+
18
+ body = querystring . stringify ( body ) ;
19
+ headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ;
22
20
} else {
23
21
/* istanbul ignore next */
24
22
if ( contentTypeKeys . length > 1 ) {
@@ -29,9 +27,7 @@ var encodeBody = function({body, headers = {}}) {
29
27
if ( headers [ contentType ] . match ( / a p p l i c a t i o n \/ j s o n / i) ) {
30
28
body = JSON . stringify ( body ) ;
31
29
} else if ( headers [ contentType ] . match ( / a p p l i c a t i o n \/ x - w w w - f o r m - u r l e n c o d e d / i) ) {
32
- body = Object . keys ( body ) . map ( function ( key ) {
33
- return `${ key } =${ encodeURIComponent ( body [ key ] ) } `
34
- } ) . join ( "&" ) ;
30
+ body = querystring . stringify ( body ) ;
35
31
}
36
32
}
37
33
return { body, headers} ;
You can’t perform that action at this time.
0 commit comments