Releases: bbc/http-transport
Releases · bbc/http-transport
v4.4.0
- use http-transport-proxy instead of https-transport-proxy, leave body as undefined instead of converting to empty string eed2dda
v4.3.0
- supports setting json opt per request 9dd0ce0
v4.2.1
- correct types 706093b
v4.2.0
feat: adds proxy support 060a6ba
v4.1.1...v4.2.0
v4.1.1
- use CJS version of node-fetch to avoid jest integration issues 7fb0c64
v4.1.0
v4.0.1
- test: add unit tests for conversion of response to json a5af740
v4.0.0
Release Notes
This major change replaces the deprecated Request library with node-fetch, since Request contains a Server-side Request Forgery (SSRF) vulnerability with no fix expected.
Key Changes:
- Setting of default behaviour of underlying transport layer is now done by passing in a configuration object, as opposed to passing in a configured instance of
request
. This removes coupling of the underlying transport layer, and your usage ofhttp-transport
. See below for more detail. - The
httpResponse
object is now returned from node-fetch rather than Request, meaning that it is different in structure. The rest of the response is left unchanged from v3.5.6. - The
asCallback()
function has been removed from theHttpTransportBuilder
. Callbackifying the client can still be achieved using the[http-transport-callbacks](https://github.com/bbc/http-transport-callbacks)
plugin.
Example of setting defaults:
const url = 'http://example.com/';
const HttpTransport = require('@bbc/http-transport');
const defaultConfig = {
agentOpts: { // Here you can pass in any options for the https agent https://nodejs.org/api/https.html#class-httpsagent
keepAlive: true,
maxSockets: 1000
},
defaults: {
json: true, // parses the response body as json, if false response body will be left as text
timeout: 2000 // sets timeout for each request
compress: true // support gzip/deflate content encoding. false to disable
}
};
const requestTransport = new HttpTransport.RequestTransport(defaultConfig);
const res = await HttpTransport.createClient(requestTransport);
.get(url)
.asResponse();
if (res.statusCode === 200) {
console.log(res.body);
}
Note: Before this major version, setting defaults was done by passing in a configured instance of request
, this meant that you could use any of requests options. This is no longer the case, however we have kept the same functionality for any of the features used in ibl.
v4.0.0-2...v4.0.0
v4.0.0-2
- catches error if JSON parsing fails, and defaults response to text a72a892
v4.0.0-1
- parse body as json if json default is set 2f68d8e