Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Don't stringify if there is not a body. #20

Open
wants to merge 1 commit into from

2 participants

@tellnes

Example:

request({ uri: 'some uri', json: true }, callback)

This will actually call JSON.stringify on null which results in the
string 'null'.

@tellnes tellnes Don't stringify if there is not a body.
Example:
```js
request({ uri: 'some uri', json: true }, callback)
```

This will actually call `JSON.stringify` on `null` which results in the
string `'null'`.
a313e3a
@Turbo87

@jhs any chance of merging this soon? We just ran into quite some trouble due to this bug. The node.js request library is not sending any body if it is null, but replacing it with browser-request suddenly introduced this difference.

We are running a server with HttpCore that actually failed with HTTP 501 Not Implemented because it received a DELETE request with a request body that was 'null'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 11, 2013
  1. @tellnes

    Don't stringify if there is not a body.

    tellnes authored
    Example:
    ```js
    request({ uri: 'some uri', json: true }, callback)
    ```
    
    This will actually call `JSON.stringify` on `null` which results in the
    string `'null'`.
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  index.js
View
2  index.js
@@ -77,7 +77,7 @@ function request(options, callback) {
if(typeof options.json !== 'boolean')
options.body = JSON.stringify(options.json)
- else if(typeof options.body !== 'string')
+ else if(typeof options.body === 'object' && options.body !== null)
options.body = JSON.stringify(options.body)
}
Something went wrong with that request. Please try again.