Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bbc/http-transport

Package Overview
Dependencies
Maintainers
21
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bbc/http-transport - npm Package Compare versions

Comparing version 4.4.1 to 4.4.2

4

index.d.ts

@@ -59,3 +59,3 @@ import * as fetch from 'node-fetch';

export declare function toJson(opts: ToJsonOpts): Plugin;
export declare function toJson(opts?: ToJsonOpts): Plugin;
export declare function logger(logger?: any): Plugin;

@@ -134,3 +134,3 @@ export declare function setContextProperty(opts: any, path: string): Plugin;

timeout(timeout: number): HttpTransportClient<ContextCurrent>;
retries(retries: number): HttpTransportClient<ContextCurrent>;
retry(retries: number): HttpTransportClient<ContextCurrent>;
retryDelay(retryDelay: number): HttpTransportClient<ContextCurrent>;

@@ -137,0 +137,0 @@ asBody(): Promise<ContextCurrent["res"]["body"]>;

@@ -53,2 +53,4 @@ 'use strict';

if (this.jsonMode(ctx)) req.addHeader('Accept', 'application/json');
if (req.hasHeaders()) opts.headers = req.getHeaders();

@@ -59,6 +61,6 @@

parseAsJson(ctx, contentType) {
jsonMode(ctx) {
if (ctx.opts?.json !== undefined) return ctx.opts.json;
return this.defaults?.json || contentType?.includes('json');
return this.defaults?.json;
}

@@ -81,3 +83,3 @@

const contentType = to.headers['content-type'];
if (this.parseAsJson(ctx, contentType)) {
if (this.jsonMode(ctx, contentType) || contentType?.includes('json')) {
try {

@@ -84,0 +86,0 @@ to.body = JSON.parse(to.body);

{
"name": "@bbc/http-transport",
"version": "4.4.1",
"version": "4.4.2",
"description": "A flexible, modular REST client built for ease-of-use and resilience.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -249,3 +249,3 @@ 'use strict';

it('allows disabling of timing request', () => {
it('allows disabling of timing request', () => {
nock.cleanAll();

@@ -292,2 +292,28 @@ api.get('/').reply(200, responseBody);

it('if json default option is passed in as true, send an accept: application/json header', () => {
nock.cleanAll();
nock(host, {
reqheaders: {
accept: 'application/json'
}
})
.get(path)
.reply(200, responseBody, header);
const ctx = createContext(url);
const options = {
defaults: {
json: true
}
};
const fetchTransport = new FetchTransport(options);
return fetchTransport
.execute(ctx)
.catch(assert.ifError)
.then((ctx) => {
assert.equal(ctx.res.statusCode, 200);
});
});
it('if there is no json default option passed in, but the content type header includes application/json, then parse body as json', () => {

@@ -294,0 +320,0 @@ nock.cleanAll();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc