From 8baa3306e80b7ba8c78ba47087d2892c372e94b4 Mon Sep 17 00:00:00 2001 From: Dan Nissenbaum Date: Mon, 22 Jun 2015 14:35:08 -0400 Subject: [PATCH 1/2] Update README.md The documentation for the 'encoding : null' argument does not emphasize that this is necessary for binary response data. See http://stackoverflow.com/a/14855016/368896. I've added a parenthetical comment to emphasize this in the documentation. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d033aeb96..e5a686bc6 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). +- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (Warning: This means that if the body of the response is binary data - for example, image data or raw data representing a PDF - you **must** set `encoding: null`.) - `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. - `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section) From 9978a480ec17dde8688a1ca6e01b4f130a1cf6de Mon Sep 17 00:00:00 2001 From: Dan Nissenbaum Date: Tue, 23 Jun 2015 09:39:23 -0400 Subject: [PATCH 2/2] Update README.md Consolidated warning about binary data and `encoding: null`. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5a686bc6..21e6d79dc 100644 --- a/README.md +++ b/README.md @@ -766,7 +766,7 @@ The first argument can be either a `url` or an `options` object. The only requir --- -- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (Warning: This means that if the body of the response is binary data - for example, image data or raw data representing a PDF - you **must** set `encoding: null`.) +- `encoding` - Encoding to be used on `setEncoding` of response data. If `null`, the `body` is returned as a `Buffer`. Anything else **(including the default value of `undefined`)** will be passed as the [encoding](http://nodejs.org/api/buffer.html#buffer_buffer) parameter to `toString()` (meaning this is effectively `utf8` by default). (**Note:** if you expect binary data, you should set `encoding: null`.) - `gzip` - If `true`, add an `Accept-Encoding` header to request compressed content encodings from the server (if not already present) and decode supported content encodings in the response. **Note:** Automatic decoding of the response content is performed on the body data returned through `request` (both through the `request` stream and passed to the callback function) but is not performed on the `response` stream (available from the `response` event) which is the unmodified `http.IncomingMessage` object which may contain compressed data. See example below. - `jar` - If `true` and `tough-cookie` is installed, remember cookies for future use (or define your custom cookie jar; see examples section)