From 7340c5d5fb48411ac49723b203273834cea90a5e Mon Sep 17 00:00:00 2001 From: John Syrinek Date: Mon, 24 Apr 2017 15:48:51 -0500 Subject: [PATCH] Adds option to specify character set in responses when using http adapter --- README.md | 4 ++++ lib/adapters/http.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f48ea58..dfe1f0a 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,10 @@ These are the available config options for making requests. Only the `url` is re // options are 'arraybuffer', 'blob', 'document', 'json', 'text', 'stream' responseType: 'json', // default + // `responseEncoding` indicates encoding to use for decoding responses + // Note: Ignored for `responseType` of 'stream' or client-side requests + responseEncoding: 'utf8', // default + // `xsrfCookieName` is the name of the cookie to use as a value for xsrf token xsrfCookieName: 'XSRF-TOKEN', // default diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 3048e57..dc360cd 100644 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -185,7 +185,7 @@ module.exports = function httpAdapter(config) { stream.on('end', function handleStreamEnd() { var responseData = Buffer.concat(responseBuffer); if (config.responseType !== 'arraybuffer') { - responseData = responseData.toString('utf8'); + responseData = responseData.toString(config.responseEncoding); } response.data = responseData;