Skip to content

Commit

Permalink
fix: upgrade http client
Browse files Browse the repository at this point in the history
https://snyksec.atlassian.net/browse/HMMR-609

Upgrading needle from 2.6.0 to 3.0.0.

This version now supports automatically parsing JSON when HTTP responses
send Content-Type application/vnd.api+json header, which the latest Snyk
APIs use.

Explicitly opting out of this automatic parsing in makeRequestRest
because this currently parses a response using Content-Type
application/text.
  • Loading branch information
gitphill committed Dec 2, 2022
1 parent 7445bc9 commit 0af535f
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 50 deletions.
190 changes: 141 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"lodash.values": "^4.3.0",
"marked": "^4.0.1",
"micromatch": "4.0.2",
"needle": "2.6.0",
"needle": "3.0.0",
"open": "^7.0.3",
"ora": "5.4.0",
"os-name": "^3.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/lib/request/promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function makeRequestRest<T>(payload: any): Promise<T> {
authorization: getAuthHeader(),
};
payload.json = true;
payload.parse = false; // do not use needle auto parser, using JSON.parse below
request.makeRequest(payload, (error, res, body) => {
if (error) {
return reject(error);
Expand Down
1 change: 1 addition & 0 deletions src/lib/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function setupRequest(payload: Payload) {
: new https.Agent({ keepAlive: true });
const options: needle.NeedleOptions = {
json: payload.json,
parse: payload.parse,
headers: payload.headers,
timeout: payload.timeout,
follow_max: 5,
Expand Down
1 change: 1 addition & 0 deletions src/lib/request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface Payload {
method: NeedleHttpVerbs;
qs?: {};
json?: boolean;
parse?: boolean;
timeout?: number;
family?: number;
noCompression?: boolean;
Expand Down

0 comments on commit 0af535f

Please sign in to comment.