@smithy/node-http-handler
Advanced tools
+14
-3
@@ -135,7 +135,18 @@ var __create = Object.create; | ||
| body.pipe(httpRequest); | ||
| } else if (body) { | ||
| return; | ||
| } | ||
| if (body) { | ||
| if (Buffer.isBuffer(body) || typeof body === "string") { | ||
| httpRequest.end(body); | ||
| return; | ||
| } | ||
| const uint8 = body; | ||
| if (typeof uint8 === "object" && uint8.buffer && typeof uint8.byteOffset === "number" && typeof uint8.byteLength === "number") { | ||
| httpRequest.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength)); | ||
| return; | ||
| } | ||
| httpRequest.end(Buffer.from(body)); | ||
| } else { | ||
| httpRequest.end(); | ||
| return; | ||
| } | ||
| httpRequest.end(); | ||
| } | ||
@@ -142,0 +153,0 @@ __name(writeBody, "writeBody"); |
@@ -52,1 +52,31 @@ import { readFileSync } from "fs"; | ||
| }; | ||
| export const createMirrorResponseFunction = (httpResp) => (request, response) => { | ||
| const bufs = []; | ||
| request.on("data", (chunk) => { | ||
| bufs.push(chunk); | ||
| }); | ||
| request.on("end", () => { | ||
| response.statusCode = httpResp.statusCode; | ||
| setResponseHeaders(response, httpResp.headers); | ||
| setResponseBody(response, Buffer.concat(bufs)); | ||
| }); | ||
| request.on("error", (err) => { | ||
| response.statusCode = 500; | ||
| setResponseHeaders(response, httpResp.headers); | ||
| setResponseBody(response, err.message); | ||
| }); | ||
| }; | ||
| export const getResponseBody = (response) => { | ||
| return new Promise((resolve, reject) => { | ||
| const bufs = []; | ||
| response.body.on("data", function (d) { | ||
| bufs.push(d); | ||
| }); | ||
| response.body.on("end", function () { | ||
| resolve(Buffer.concat(bufs).toString()); | ||
| }); | ||
| response.body.on("error", (err) => { | ||
| reject(err); | ||
| }); | ||
| }); | ||
| }; |
@@ -33,9 +33,21 @@ import { Readable } from "stream"; | ||
| body.pipe(httpRequest); | ||
| return; | ||
| } | ||
| else if (body) { | ||
| if (body) { | ||
| if (Buffer.isBuffer(body) || typeof body === "string") { | ||
| httpRequest.end(body); | ||
| return; | ||
| } | ||
| const uint8 = body; | ||
| if (typeof uint8 === "object" && | ||
| uint8.buffer && | ||
| typeof uint8.byteOffset === "number" && | ||
| typeof uint8.byteLength === "number") { | ||
| httpRequest.end(Buffer.from(uint8.buffer, uint8.byteOffset, uint8.byteLength)); | ||
| return; | ||
| } | ||
| httpRequest.end(Buffer.from(body)); | ||
| return; | ||
| } | ||
| else { | ||
| httpRequest.end(); | ||
| } | ||
| httpRequest.end(); | ||
| } |
@@ -11,1 +11,3 @@ import { HttpResponse } from "@smithy/types"; | ||
| export declare const createMockHttp2Server: () => Http2Server; | ||
| export declare const createMirrorResponseFunction: (httpResp: HttpResponse) => (request: IncomingMessage, response: ServerResponse) => void; | ||
| export declare const getResponseBody: (response: HttpResponse) => Promise<string>; |
@@ -11,1 +11,3 @@ import { HttpResponse } from "@smithy/types"; | ||
| export declare const createMockHttp2Server: () => Http2Server; | ||
| export declare const createMirrorResponseFunction: (httpResp: HttpResponse) => (request: IncomingMessage, response: ServerResponse) => void; | ||
| export declare const getResponseBody: (response: HttpResponse) => Promise<string>; |
+1
-1
| { | ||
| "name": "@smithy/node-http-handler", | ||
| "version": "2.4.2", | ||
| "version": "2.4.3", | ||
| "description": "Provides a way to make requests", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 3 instances in 1 package
84909
2.73%1793
3.28%