Download node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js from sweet2004/bot: direct link, hf CLI and curl.
- Browser
- Download file 4.91 kB
-
https://huggingface.co/spaces/sweet2004/bot/resolve/main/node_modules/%40aws-sdk/node-http-handler/dist-cjs/node-http-handler.js
- Command line
-
hf download hf://spaces/sweet2004/bot/node_modules/@aws-sdk/node-http-handler/dist-cjs/node-http-handler.js
-
curl -L -o node-http-handler.js https://huggingface.co/spaces/sweet2004/bot/resolve/main/node_modules/%40aws-sdk/node-http-handler/dist-cjs/node-http-handler.js
4.91 kB
| ; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.NodeHttpHandler = exports.DEFAULT_REQUEST_TIMEOUT = void 0; | |
| const protocol_http_1 = require("@aws-sdk/protocol-http"); | |
| const querystring_builder_1 = require("@aws-sdk/querystring-builder"); | |
| const http_1 = require("http"); | |
| const https_1 = require("https"); | |
| const constants_1 = require("./constants"); | |
| const get_transformed_headers_1 = require("./get-transformed-headers"); | |
| const write_request_body_1 = require("./write-request-body"); | |
| exports.DEFAULT_REQUEST_TIMEOUT = 0; | |
| class NodeHttpHandler { | |
| constructor(options) { | |
| this.metadata = { handlerProtocol: "http/1.1" }; | |
| this.configProvider = new Promise((resolve, reject) => { | |
| if (typeof options === "function") { | |
| options() | |
| .then((_options) => { | |
| resolve(this.resolveDefaultConfig(_options)); | |
| }) | |
| .catch(reject); | |
| } | |
| else { | |
| resolve(this.resolveDefaultConfig(options)); | |
| } | |
| }); | |
| } | |
| resolveDefaultConfig(options) { | |
| var _a, _b; | |
| const { requestTimeout, connectionTimeout, socketTimeout, httpAgent, httpsAgent } = options || {}; | |
| const keepAlive = true; | |
| const maxSockets = 50; | |
| return { | |
| connectionTimeout, | |
| socketTimeout, | |
| requestTimeout: (_b = (_a = requestTimeout !== null && requestTimeout !== void 0 ? requestTimeout : connectionTimeout) !== null && _a !== void 0 ? _a : socketTimeout) !== null && _b !== void 0 ? _b : exports.DEFAULT_REQUEST_TIMEOUT, | |
| httpAgent: httpAgent || new http_1.Agent({ keepAlive, maxSockets }), | |
| httpsAgent: httpsAgent || new https_1.Agent({ keepAlive, maxSockets }), | |
| }; | |
| } | |
| destroy() { | |
| var _a, _b, _c, _d; | |
| (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.httpAgent) === null || _b === void 0 ? void 0 : _b.destroy(); | |
| (_d = (_c = this.config) === null || _c === void 0 ? void 0 : _c.httpsAgent) === null || _d === void 0 ? void 0 : _d.destroy(); | |
| } | |
| async handle(request, { abortSignal } = {}) { | |
| if (!this.config) { | |
| this.config = await this.configProvider; | |
| } | |
| return new Promise((resolve, reject) => { | |
| var _a, _b; | |
| if (!this.config) { | |
| throw new Error("Node HTTP request handler config is not resolved"); | |
| } | |
| if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) { | |
| const abortError = new Error("Request aborted"); | |
| abortError.name = "AbortError"; | |
| reject(abortError); | |
| return; | |
| } | |
| const isSSL = request.protocol === "https:"; | |
| const queryString = (0, querystring_builder_1.buildQueryString)(request.query || {}); | |
| const nodeHttpsOptions = { | |
| headers: request.headers, | |
| host: request.hostname, | |
| method: request.method, | |
| path: queryString ? `${request.path}?${queryString}` : request.path, | |
| port: request.port, | |
| agent: isSSL ? this.config.httpsAgent : this.config.httpAgent, | |
| }; | |
| const requestFunc = isSSL ? https_1.request : http_1.request; | |
| const req = requestFunc(nodeHttpsOptions, (res) => { | |
| const httpResponse = new protocol_http_1.HttpResponse({ | |
| statusCode: res.statusCode || -1, | |
| headers: (0, get_transformed_headers_1.getTransformedHeaders)(res.headers), | |
| body: res, | |
| }); | |
| resolve({ response: httpResponse }); | |
| }); | |
| req.on("error", (err) => { | |
| if (constants_1.NODEJS_TIMEOUT_ERROR_CODES.includes(err.code)) { | |
| reject(Object.assign(err, { name: "TimeoutError" })); | |
| } | |
| else { | |
| reject(err); | |
| } | |
| }); | |
| const timeout = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.requestTimeout) !== null && _b !== void 0 ? _b : exports.DEFAULT_REQUEST_TIMEOUT; | |
| req.setTimeout(timeout, () => { | |
| req.destroy(); | |
| reject(Object.assign(new Error(`Connection timed out after ${timeout} ms`), { name: "TimeoutError" })); | |
| }); | |
| if (abortSignal) { | |
| abortSignal.onabort = () => { | |
| req.abort(); | |
| const abortError = new Error("Request aborted"); | |
| abortError.name = "AbortError"; | |
| reject(abortError); | |
| }; | |
| } | |
| (0, write_request_body_1.writeRequestBody)(req, request); | |
| }); | |
| } | |
| } | |
| exports.NodeHttpHandler = NodeHttpHandler; | |