lightning-request-net
Advanced tools
Comparing version 0.2.1 to 0.2.2
{ | ||
"name": "lightning-request-net", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Lightweight Node.js HTTP client based on net.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,3 +6,3 @@ const CRLF = '\r\n'; | ||
module.exports = { | ||
encode: function(options) { | ||
encode: function (options) { | ||
options.headers = options.headers || {}; | ||
@@ -16,3 +16,3 @@ const chunkedEncoding = options.headers['Transfer-Encoding'] === 'chunked'; | ||
let data = `${options.method} ${options.path} HTTP/1.1${CRLF}`; | ||
Object.keys(options.headers).forEach(key => { | ||
Object.keys(options.headers).forEach((key) => { | ||
data += `${key}: ${options.headers[key]}${CRLF}`; | ||
@@ -36,3 +36,3 @@ }); | ||
decode: function(data) { | ||
decode: function (data) { | ||
const idx = data.indexOf(CRLF); | ||
@@ -51,5 +51,10 @@ const idx2 = data.indexOf(CRLF_2); | ||
let headers = {}; | ||
responseHeadersText.split(CRLF).forEach(item => { | ||
responseHeadersText.split(CRLF).forEach((item) => { | ||
const index = item.indexOf(': '); | ||
headers[item.slice(0, index)] = item.slice(index + 2); | ||
const key = item.slice(0, index).toLowerCase(); | ||
if (headers[key]) { | ||
headers[key] = headers[key] + ', ' + item.slice(index + 2); | ||
} else { | ||
headers[key] = item.slice(index + 2); | ||
} | ||
}); | ||
@@ -56,0 +61,0 @@ if (headers['Transfer-Encoding']) { |
27424
330