@smithy/node-http-handler
Advanced tools
+45
-25
| 'use strict'; | ||
| var protocolHttp = require('@smithy/protocol-http'); | ||
| var querystringBuilder = require('@smithy/querystring-builder'); | ||
| var node_https = require('node:https'); | ||
| var protocols = require('@smithy/core/protocols'); | ||
| var node_stream = require('node:stream'); | ||
@@ -33,3 +32,3 @@ var http2 = require('node:http2'); | ||
| const transformedHeaders = {}; | ||
| for (const name of Object.keys(headers)) { | ||
| for (const name in headers) { | ||
| const headerValues = headers[name]; | ||
@@ -150,4 +149,4 @@ transformedHeaders[name] = Array.isArray(headerValues) ? headerValues.join(",") : headerValues; | ||
| async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) { | ||
| const headers = request.headers ?? {}; | ||
| const expect = headers.Expect || headers.expect; | ||
| const headers = request.headers; | ||
| const expect = headers ? headers.Expect || headers.expect : undefined; | ||
| let timeoutId = -1; | ||
@@ -278,6 +277,17 @@ let sendBody = true; | ||
| let writeRequestBodyPromise = undefined; | ||
| const timeouts = []; | ||
| let socketWarningTimeoutId = -1; | ||
| let connectionTimeoutId = -1; | ||
| let requestTimeoutId = -1; | ||
| let socketTimeoutId = -1; | ||
| let keepAliveTimeoutId = -1; | ||
| const clearTimeouts = () => { | ||
| timing.clearTimeout(socketWarningTimeoutId); | ||
| timing.clearTimeout(connectionTimeoutId); | ||
| timing.clearTimeout(requestTimeoutId); | ||
| timing.clearTimeout(socketTimeoutId); | ||
| timing.clearTimeout(keepAliveTimeoutId); | ||
| }; | ||
| const resolve = async (arg) => { | ||
| await writeRequestBodyPromise; | ||
| timeouts.forEach(timing.clearTimeout); | ||
| clearTimeouts(); | ||
| _resolve(arg); | ||
@@ -287,3 +297,3 @@ }; | ||
| await writeRequestBodyPromise; | ||
| timeouts.forEach(timing.clearTimeout); | ||
| clearTimeouts(); | ||
| _reject(arg); | ||
@@ -296,4 +306,4 @@ }; | ||
| } | ||
| const headers = request.headers ?? {}; | ||
| const expectContinue = (headers.Expect ?? headers.expect) === "100-continue"; | ||
| const headers = request.headers; | ||
| const expectContinue = headers ? (headers.Expect ?? headers.expect) === "100-continue" : false; | ||
| let agent = isSSL ? config.httpsAgent : config.httpAgent; | ||
@@ -306,6 +316,6 @@ if (expectContinue && !this.externalAgent) { | ||
| } | ||
| timeouts.push(timing.setTimeout(() => { | ||
| socketWarningTimeoutId = timing.setTimeout(() => { | ||
| this.socketWarningTimestamp = NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, config.logger); | ||
| }, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2000) + (config.connectionTimeout ?? 1000))); | ||
| const queryString = querystringBuilder.buildQueryString(request.query || {}); | ||
| }, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2000) + (config.connectionTimeout ?? 1000)); | ||
| const queryString = request.query ? protocols.buildQueryString(request.query) : ""; | ||
| let auth = undefined; | ||
@@ -342,3 +352,3 @@ if (request.username != null || request.password != null) { | ||
| const req = requestFunc(nodeHttpsOptions, (res) => { | ||
| const httpResponse = new protocolHttp.HttpResponse({ | ||
| const httpResponse = new protocols.HttpResponse({ | ||
| statusCode: res.statusCode || -1, | ||
@@ -375,14 +385,14 @@ reason: res.statusMessage, | ||
| const effectiveRequestTimeout = requestTimeout ?? config.requestTimeout; | ||
| timeouts.push(setConnectionTimeout(req, reject, config.connectionTimeout)); | ||
| timeouts.push(setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console)); | ||
| timeouts.push(setSocketTimeout(req, reject, config.socketTimeout)); | ||
| connectionTimeoutId = setConnectionTimeout(req, reject, config.connectionTimeout); | ||
| requestTimeoutId = setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console); | ||
| socketTimeoutId = setSocketTimeout(req, reject, config.socketTimeout); | ||
| const httpAgent = nodeHttpsOptions.agent; | ||
| if (typeof httpAgent === "object" && "keepAlive" in httpAgent) { | ||
| timeouts.push(setSocketKeepAlive(req, { | ||
| keepAliveTimeoutId = setSocketKeepAlive(req, { | ||
| keepAlive: httpAgent.keepAlive, | ||
| keepAliveMsecs: httpAgent.keepAliveMsecs, | ||
| })); | ||
| }); | ||
| } | ||
| writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout, this.externalAgent).catch((e) => { | ||
| timeouts.forEach(timing.clearTimeout); | ||
| clearTimeouts(); | ||
| return _reject(e); | ||
@@ -535,2 +545,3 @@ }); | ||
| config; | ||
| connectOptions; | ||
| connectionPools = new Map(); | ||
@@ -553,3 +564,3 @@ constructor(config) { | ||
| } | ||
| const ref = new ClientHttp2SessionRef(http2.connect(url)); | ||
| const ref = new ClientHttp2SessionRef(this.connect(url)); | ||
| const session = ref.deref(); | ||
@@ -588,3 +599,3 @@ if (this.config.maxConcurrency) { | ||
| const url = this.getUrlString(requestContext); | ||
| const ref = new ClientHttp2SessionRef(http2.connect(url)); | ||
| const ref = new ClientHttp2SessionRef(this.connect(url)); | ||
| const session = ref.deref(); | ||
@@ -624,2 +635,5 @@ session.settings({ maxConcurrentStreams: 1 }); | ||
| } | ||
| setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions) { | ||
| this.connectOptions = nodeHttp2ConnectOptions; | ||
| } | ||
| debug() { | ||
@@ -662,2 +676,5 @@ const pools = {}; | ||
| } | ||
| connect(url) { | ||
| return this.connectOptions === undefined ? http2.connect(url) : http2.connect(url, this.connectOptions); | ||
| } | ||
| } | ||
@@ -696,3 +713,3 @@ | ||
| this.config = await this.configProvider; | ||
| const { disableConcurrentStreams, maxConcurrentStreams } = this.config; | ||
| const { disableConcurrentStreams, maxConcurrentStreams, nodeHttp2ConnectOptions } = this.config; | ||
| this.connectionManager.setDisableConcurrentStreams(disableConcurrentStreams ?? false); | ||
@@ -702,2 +719,5 @@ if (maxConcurrentStreams) { | ||
| } | ||
| if (nodeHttp2ConnectOptions) { | ||
| this.connectionManager.setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions); | ||
| } | ||
| } | ||
@@ -748,3 +768,3 @@ const { requestTimeout: configRequestTimeout, disableConcurrentStreams } = this.config; | ||
| }; | ||
| const queryString = querystringBuilder.buildQueryString(query ?? {}); | ||
| const queryString = query ? protocols.buildQueryString(query) : ""; | ||
| let path = request.path; | ||
@@ -793,3 +813,3 @@ if (queryString) { | ||
| clientHttp2Stream.on("response", (headers) => { | ||
| const httpResponse = new protocolHttp.HttpResponse({ | ||
| const httpResponse = new protocols.HttpResponse({ | ||
| statusCode: headers[":status"] ?? -1, | ||
@@ -796,0 +816,0 @@ headers: getTransformedHeaders(headers), |
| const getTransformedHeaders = (headers) => { | ||
| const transformedHeaders = {}; | ||
| for (const name of Object.keys(headers)) { | ||
| for (const name in headers) { | ||
| const headerValues = headers[name]; | ||
@@ -5,0 +5,0 @@ transformedHeaders[name] = Array.isArray(headerValues) ? headerValues.join(",") : headerValues; |
@@ -1,4 +0,3 @@ | ||
| import { HttpResponse } from "@smithy/protocol-http"; | ||
| import { buildQueryString } from "@smithy/querystring-builder"; | ||
| import { Agent as hsAgent, request as hsRequest } from "node:https"; | ||
| import { HttpResponse, buildQueryString } from "@smithy/core/protocols"; | ||
| import { buildAbortError } from "./build-abort-error"; | ||
@@ -80,6 +79,17 @@ import { NODEJS_TIMEOUT_ERROR_CODES } from "./constants"; | ||
| let writeRequestBodyPromise = undefined; | ||
| const timeouts = []; | ||
| let socketWarningTimeoutId = -1; | ||
| let connectionTimeoutId = -1; | ||
| let requestTimeoutId = -1; | ||
| let socketTimeoutId = -1; | ||
| let keepAliveTimeoutId = -1; | ||
| const clearTimeouts = () => { | ||
| timing.clearTimeout(socketWarningTimeoutId); | ||
| timing.clearTimeout(connectionTimeoutId); | ||
| timing.clearTimeout(requestTimeoutId); | ||
| timing.clearTimeout(socketTimeoutId); | ||
| timing.clearTimeout(keepAliveTimeoutId); | ||
| }; | ||
| const resolve = async (arg) => { | ||
| await writeRequestBodyPromise; | ||
| timeouts.forEach(timing.clearTimeout); | ||
| clearTimeouts(); | ||
| _resolve(arg); | ||
@@ -89,3 +99,3 @@ }; | ||
| await writeRequestBodyPromise; | ||
| timeouts.forEach(timing.clearTimeout); | ||
| clearTimeouts(); | ||
| _reject(arg); | ||
@@ -98,4 +108,4 @@ }; | ||
| } | ||
| const headers = request.headers ?? {}; | ||
| const expectContinue = (headers.Expect ?? headers.expect) === "100-continue"; | ||
| const headers = request.headers; | ||
| const expectContinue = headers ? (headers.Expect ?? headers.expect) === "100-continue" : false; | ||
| let agent = isSSL ? config.httpsAgent : config.httpAgent; | ||
@@ -108,6 +118,6 @@ if (expectContinue && !this.externalAgent) { | ||
| } | ||
| timeouts.push(timing.setTimeout(() => { | ||
| socketWarningTimeoutId = timing.setTimeout(() => { | ||
| this.socketWarningTimestamp = NodeHttpHandler.checkSocketUsage(agent, this.socketWarningTimestamp, config.logger); | ||
| }, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2000) + (config.connectionTimeout ?? 1000))); | ||
| const queryString = buildQueryString(request.query || {}); | ||
| }, config.socketAcquisitionWarningTimeout ?? (config.requestTimeout ?? 2000) + (config.connectionTimeout ?? 1000)); | ||
| const queryString = request.query ? buildQueryString(request.query) : ""; | ||
| let auth = undefined; | ||
@@ -176,14 +186,14 @@ if (request.username != null || request.password != null) { | ||
| const effectiveRequestTimeout = requestTimeout ?? config.requestTimeout; | ||
| timeouts.push(setConnectionTimeout(req, reject, config.connectionTimeout)); | ||
| timeouts.push(setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console)); | ||
| timeouts.push(setSocketTimeout(req, reject, config.socketTimeout)); | ||
| connectionTimeoutId = setConnectionTimeout(req, reject, config.connectionTimeout); | ||
| requestTimeoutId = setRequestTimeout(req, reject, effectiveRequestTimeout, config.throwOnRequestTimeout, config.logger ?? console); | ||
| socketTimeoutId = setSocketTimeout(req, reject, config.socketTimeout); | ||
| const httpAgent = nodeHttpsOptions.agent; | ||
| if (typeof httpAgent === "object" && "keepAlive" in httpAgent) { | ||
| timeouts.push(setSocketKeepAlive(req, { | ||
| keepAliveTimeoutId = setSocketKeepAlive(req, { | ||
| keepAlive: httpAgent.keepAlive, | ||
| keepAliveMsecs: httpAgent.keepAliveMsecs, | ||
| })); | ||
| }); | ||
| } | ||
| writeRequestBodyPromise = writeRequestBody(req, request, effectiveRequestTimeout, this.externalAgent).catch((e) => { | ||
| timeouts.forEach(timing.clearTimeout); | ||
| clearTimeouts(); | ||
| return _reject(e); | ||
@@ -190,0 +200,0 @@ }); |
@@ -6,2 +6,3 @@ import http2 from "node:http2"; | ||
| config; | ||
| connectOptions; | ||
| connectionPools = new Map(); | ||
@@ -24,3 +25,3 @@ constructor(config) { | ||
| } | ||
| const ref = new ClientHttp2SessionRef(http2.connect(url)); | ||
| const ref = new ClientHttp2SessionRef(this.connect(url)); | ||
| const session = ref.deref(); | ||
@@ -59,3 +60,3 @@ if (this.config.maxConcurrency) { | ||
| const url = this.getUrlString(requestContext); | ||
| const ref = new ClientHttp2SessionRef(http2.connect(url)); | ||
| const ref = new ClientHttp2SessionRef(this.connect(url)); | ||
| const session = ref.deref(); | ||
@@ -95,2 +96,5 @@ session.settings({ maxConcurrentStreams: 1 }); | ||
| } | ||
| setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions) { | ||
| this.connectOptions = nodeHttp2ConnectOptions; | ||
| } | ||
| debug() { | ||
@@ -133,2 +137,5 @@ const pools = {}; | ||
| } | ||
| connect(url) { | ||
| return this.connectOptions === undefined ? http2.connect(url) : http2.connect(url, this.connectOptions); | ||
| } | ||
| } |
@@ -1,4 +0,3 @@ | ||
| import { HttpResponse } from "@smithy/protocol-http"; | ||
| import { buildQueryString } from "@smithy/querystring-builder"; | ||
| import { constants } from "node:http2"; | ||
| import { HttpResponse, buildQueryString } from "@smithy/core/protocols"; | ||
| import { buildAbortError } from "./build-abort-error"; | ||
@@ -39,3 +38,3 @@ import { getTransformedHeaders } from "./get-transformed-headers"; | ||
| this.config = await this.configProvider; | ||
| const { disableConcurrentStreams, maxConcurrentStreams } = this.config; | ||
| const { disableConcurrentStreams, maxConcurrentStreams, nodeHttp2ConnectOptions } = this.config; | ||
| this.connectionManager.setDisableConcurrentStreams(disableConcurrentStreams ?? false); | ||
@@ -45,2 +44,5 @@ if (maxConcurrentStreams) { | ||
| } | ||
| if (nodeHttp2ConnectOptions) { | ||
| this.connectionManager.setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions); | ||
| } | ||
| } | ||
@@ -91,3 +93,3 @@ const { requestTimeout: configRequestTimeout, disableConcurrentStreams } = this.config; | ||
| }; | ||
| const queryString = buildQueryString(query ?? {}); | ||
| const queryString = query ? buildQueryString(query) : ""; | ||
| let path = request.path; | ||
@@ -94,0 +96,0 @@ if (queryString) { |
| import { readFileSync } from "node:fs"; | ||
| import { createServer as createHttpServer } from "node:http"; | ||
| import { createServer as createHttp2Server } from "node:http2"; | ||
| import { createServer as createHttpServer, } from "node:http"; | ||
| import { createServer as createHttpsServer } from "node:https"; | ||
@@ -5,0 +5,0 @@ import { join } from "node:path"; |
@@ -5,4 +5,4 @@ import { Readable } from "node:stream"; | ||
| export async function writeRequestBody(httpRequest, request, maxContinueTimeoutMs = MIN_WAIT_TIME, externalAgent = false) { | ||
| const headers = request.headers ?? {}; | ||
| const expect = headers.Expect || headers.expect; | ||
| const headers = request.headers; | ||
| const expect = headers ? headers.Expect || headers.expect : undefined; | ||
| let timeoutId = -1; | ||
@@ -9,0 +9,0 @@ let sendBody = true; |
@@ -0,4 +1,4 @@ | ||
| import type { IncomingHttpHeaders } from "node:http2"; | ||
| import type { HeaderBag } from "@smithy/types"; | ||
| import type { IncomingHttpHeaders } from "node:http2"; | ||
| declare const getTransformedHeaders: (headers: IncomingHttpHeaders) => HeaderBag; | ||
| export { getTransformedHeaders }; |
@@ -1,6 +0,5 @@ | ||
| import type { HttpHandler, HttpRequest } from "@smithy/protocol-http"; | ||
| import { HttpResponse } from "@smithy/protocol-http"; | ||
| import type { HttpHandlerOptions, Logger, NodeHttpHandlerOptions, Provider } from "@smithy/types"; | ||
| import type { Agent as hAgentType } from "node:http"; | ||
| import { Agent as hsAgent } from "node:https"; | ||
| import { HttpResponse, type HttpHandler, type HttpRequest } from "@smithy/core/protocols"; | ||
| import type { HttpHandlerOptions, Logger, NodeHttpHandlerOptions, Provider } from "@smithy/types"; | ||
| export { NodeHttpHandlerOptions }; | ||
@@ -7,0 +6,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
| import { type ClientSessionOptions, type SecureClientSessionOptions } from "node:http2"; | ||
| import type { ConnectConfiguration, ConnectionManager, ConnectionManagerConfiguration, RequestContext } from "@smithy/types"; | ||
@@ -12,2 +13,3 @@ import { ClientHttp2SessionRef } from "./http2/ClientHttp2SessionRef"; | ||
| private config; | ||
| private connectOptions?; | ||
| private readonly connectionPools; | ||
@@ -34,2 +36,3 @@ constructor(config: ConnectionManagerConfiguration); | ||
| setDisableConcurrentStreams(disableConcurrentStreams: boolean): void; | ||
| setNodeHttp2ConnectOptions(nodeHttp2ConnectOptions: Partial<SecureClientSessionOptions | ClientSessionOptions>): void; | ||
| /** | ||
@@ -44,2 +47,3 @@ * @internal | ||
| private getUrlString; | ||
| private connect; | ||
| } |
@@ -0,3 +1,3 @@ | ||
| import type { ClientHttp2Session } from "node:http2"; | ||
| import type { ConnectionPool } from "@smithy/types"; | ||
| import type { ClientHttp2Session } from "node:http2"; | ||
| import { ClientHttp2SessionRef } from "./http2/ClientHttp2SessionRef"; | ||
@@ -4,0 +4,0 @@ /** |
@@ -1,3 +0,3 @@ | ||
| import type { HttpHandler, HttpRequest } from "@smithy/protocol-http"; | ||
| import { HttpResponse } from "@smithy/protocol-http"; | ||
| import { type ClientSessionOptions, type SecureClientSessionOptions } from "node:http2"; | ||
| import { HttpResponse, type HttpHandler, type HttpRequest } from "@smithy/core/protocols"; | ||
| import type { HttpHandlerOptions, Provider } from "@smithy/types"; | ||
@@ -34,2 +34,7 @@ /** | ||
| maxConcurrentStreams?: number; | ||
| /** | ||
| * A set of raw options that will be passed to http2.connect. | ||
| * https://nodejs.org/api/http2.html#http2connectauthority-options-listener | ||
| */ | ||
| nodeHttp2ConnectOptions?: Partial<SecureClientSessionOptions | ClientSessionOptions>; | ||
| } | ||
@@ -36,0 +41,0 @@ /** |
@@ -1,3 +0,2 @@ | ||
| import type { ReadableOptions } from "node:stream"; | ||
| import { Readable } from "node:stream"; | ||
| import { Readable, type ReadableOptions } from "node:stream"; | ||
| export interface ReadFromBuffersOptions extends ReadableOptions { | ||
@@ -4,0 +3,0 @@ buffers: Buffer[]; |
@@ -0,5 +1,5 @@ | ||
| import { type Http2Server } from "node:http2"; | ||
| import { type Server as HttpServer, type IncomingMessage, type ServerResponse } from "node:http"; | ||
| import { type Server as HttpsServer } from "node:https"; | ||
| import type { HttpResponse } from "@smithy/types"; | ||
| import type { IncomingMessage, Server as HttpServer, ServerResponse } from "node:http"; | ||
| import type { Http2Server } from "node:http2"; | ||
| import type { Server as HttpsServer } from "node:https"; | ||
| export declare const createResponseFunction: (httpResp: HttpResponse) => (request: IncomingMessage, response: ServerResponse) => void; | ||
@@ -6,0 +6,0 @@ export declare const createResponseFunctionWithDelay: (httpResp: HttpResponse, delay: number) => (request: IncomingMessage, response: ServerResponse) => void; |
@@ -0,3 +1,3 @@ | ||
| import type { ClientRequest } from "node:http"; | ||
| import type { Logger } from "@smithy/types"; | ||
| import type { ClientRequest } from "node:http"; | ||
| /** | ||
@@ -4,0 +4,0 @@ * @internal |
@@ -1,3 +0,2 @@ | ||
| import type { ReadableOptions } from "node:stream"; | ||
| import { Readable } from "node:stream"; | ||
| import { Readable, type ReadableOptions } from "node:stream"; | ||
| export interface ReadFromBuffersOptions extends ReadableOptions { | ||
@@ -4,0 +3,0 @@ buffers: Buffer[]; |
@@ -0,4 +1,4 @@ | ||
| import type { ClientHttp2Stream } from "node:http2"; | ||
| import type { ClientRequest } from "node:http"; | ||
| import type { HttpRequest } from "@smithy/types"; | ||
| import type { ClientRequest } from "node:http"; | ||
| import type { ClientHttp2Stream } from "node:http2"; | ||
| /** | ||
@@ -5,0 +5,0 @@ * This resolves when writeBody has been called. |
+2
-3
| { | ||
| "name": "@smithy/node-http-handler", | ||
| "version": "4.6.1", | ||
| "version": "4.7.0", | ||
| "description": "Provides a way to make requests", | ||
@@ -29,4 +29,3 @@ "scripts": { | ||
| "dependencies": { | ||
| "@smithy/protocol-http": "^5.3.14", | ||
| "@smithy/querystring-builder": "^4.2.14", | ||
| "@smithy/core": "^3.24.0", | ||
| "@smithy/types": "^4.14.1", | ||
@@ -33,0 +32,0 @@ "tslib": "^2.6.2" |
100979
2.2%3
-25%2248
2.04%+ Added
- Removed
- Removed
- Removed
- Removed