@bbc/http-transport
Advanced tools
Comparing version 4.0.0-1 to 4.0.0-2
@@ -65,7 +65,9 @@ 'use strict'; | ||
// currently supports json and text formats only | ||
to.body = await from.text(); | ||
const contentType = to.headers['content-type']; | ||
if (this.defaults?.json || contentType?.includes('json')) { | ||
to.body = await from.json(); | ||
} else { | ||
to.body = await from.text(); | ||
try { | ||
to.body = JSON.parse(to.body); | ||
} catch {} // If body is not parseable, leave as text | ||
} | ||
@@ -72,0 +74,0 @@ |
{ | ||
"name": "@bbc/http-transport", | ||
"version": "4.0.0-1", | ||
"version": "4.0.0-2", | ||
"description": "A flexible, modular REST client built for ease-of-use and resilience.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -78,2 +78,13 @@ 'use strict'; | ||
it('handles an empty response body when parsing as JSON', async () => { | ||
nock.cleanAll(); | ||
api.get(path).reply(200, undefined, defaultHeaders); | ||
const res = await HttpTransport.createClient() | ||
.get(url) | ||
.asResponse(); | ||
assert.deepEqual(res.body, ''); | ||
}); | ||
it('sets a default User-agent for every request', async () => { | ||
@@ -80,0 +91,0 @@ nock.cleanAll(); |
380924
6619