@smithy/node-http-handler
Advanced tools
Comparing version 2.4.2 to 2.4.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>; |
{ | ||
"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": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84909
1793