@bbc/http-transport
Advanced tools
Comparing version 3.5.7-2 to 3.5.7-3
@@ -57,3 +57,2 @@ 'use strict'; | ||
const to = ctx.res; | ||
const contentType = from.headers?.get('content-type'); | ||
REQUIRED_PROPERTIES.forEach((property) => { | ||
@@ -64,10 +63,10 @@ to[property] = from[property]; | ||
to.statusCode = from.status; | ||
to.headers = Object.fromEntries(from.headers.entries()); | ||
// currently supports json and text formats only | ||
if (from.ok) { | ||
if (contentType?.includes('json')) { | ||
to.body = await from.json(); | ||
} else if (contentType?.includes('text')) { | ||
to.body = await from.text(); | ||
} | ||
const contentType = to.headers['content-type']; | ||
if (contentType?.includes('json')) { | ||
to.body = await from.json(); | ||
} else if (contentType?.includes('text')) { | ||
to.body = await from.text(); | ||
} | ||
@@ -74,0 +73,0 @@ |
{ | ||
"name": "@bbc/http-transport", | ||
"version": "3.5.7-2", | ||
"version": "3.5.7-3", | ||
"description": "A flexible, modular REST client built for ease-of-use and resilience.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,2 +26,3 @@ 'use strict'; | ||
const responseBody = requestBody; | ||
const defaultHeaders = { 'Content-Type': 'application/json' }; | ||
@@ -43,3 +44,3 @@ function toUpperCase() { | ||
.reply(500); | ||
api[httpMethod](path).reply(successCode, simpleResponseBody); | ||
api[httpMethod](path).reply(successCode, simpleResponseBody, defaultHeaders); | ||
} | ||
@@ -56,3 +57,3 @@ | ||
.reply(200); | ||
api[httpMethod](path).reply(successCode, simpleResponseBody); | ||
api[httpMethod](path).reply(successCode, simpleResponseBody, defaultHeaders); | ||
} | ||
@@ -64,8 +65,3 @@ | ||
nock.cleanAll(); | ||
api | ||
.get(path) | ||
.reply(200, simpleResponseBody) | ||
.defaultReplyHeaders({ | ||
'Content-Type': 'application/json' | ||
}); | ||
api.get(path).reply(200, simpleResponseBody, defaultHeaders); | ||
}); | ||
@@ -598,8 +594,3 @@ | ||
nock.cleanAll(); | ||
api | ||
.defaultReplyHeaders({ | ||
'Content-Type': 'application/json' | ||
}) | ||
.get(path) | ||
.reply(200, responseBody); | ||
api.get(path).reply(200, responseBody, defaultHeaders); | ||
@@ -606,0 +597,0 @@ const client = HttpTransport.createBuilder() |
380573
6610