@effect-aws/http-handler 0.1.2 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/dts/HttpHandler.d.ts +1 -1
- package/dist/dts/HttpHandler.d.ts.map +1 -1
- package/dist/dts/internal/httpHandler.d.ts +1 -1
- package/dist/dts/internal/httpHandler.d.ts.map +1 -1
- package/dist/esm/internal/httpHandler.js +4 -4
- package/dist/esm/internal/httpHandler.js.map +1 -1
- package/package.json +8 -12
- package/src/internal/httpHandler.ts +9 -8
- package/dist/cjs/HttpHandler.d.ts +0 -12
- package/dist/cjs/HttpHandler.d.ts.map +0 -1
- package/dist/cjs/HttpHandler.js +0 -13
- package/dist/cjs/HttpHandler.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.d.ts.map +0 -1
- package/dist/cjs/index.js +0 -31
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internal/httpHandler.d.ts +0 -15
- package/dist/cjs/internal/httpHandler.d.ts.map +0 -1
- package/dist/cjs/internal/httpHandler.js +0 -52
- package/dist/cjs/internal/httpHandler.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -8,5 +8,5 @@ import { Layer } from "effect";
|
|
|
8
8
|
* @since 0.1.0
|
|
9
9
|
* @category layers
|
|
10
10
|
*/
|
|
11
|
-
export declare const layer: (config?: HttpHandlerOptions) => Layer.Layer<HttpHandler.RequestHandler, never, import("
|
|
11
|
+
export declare const layer: (config?: HttpHandlerOptions) => Layer.Layer<HttpHandler.RequestHandler, never, import("effect/unstable/http/HttpClient").HttpClient>;
|
|
12
12
|
//# sourceMappingURL=HttpHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpHandler.d.ts","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG/B;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,kBAAkB,
|
|
1
|
+
{"version":3,"file":"HttpHandler.d.ts","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG/B;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,kBAAkB,yGACqC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpHandler.d.ts","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":"AAWA,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"httpHandler.d.ts","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":"AAWA,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAU,kBAAkB;QAC1B;;WAEG;QACH,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC;QAE5B;;;WAGG;QACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;KAC/B;CACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { HttpHandler } from "@effect-aws/commons";
|
|
2
|
-
import { HttpBody, HttpClient, HttpClientRequest } from "@effect/platform";
|
|
3
2
|
import { HttpResponse } from "@smithy/protocol-http";
|
|
4
3
|
import { buildQueryString } from "@smithy/querystring-builder";
|
|
5
4
|
import { Duration, Effect, Option, Sink, Stream } from "effect";
|
|
5
|
+
import { HttpBody, HttpClient, HttpClientError, HttpClientRequest } from "effect/unstable/http";
|
|
6
6
|
const makeUrl = (request) => {
|
|
7
7
|
let path = request.path;
|
|
8
8
|
const queryString = buildQueryString(request.query || {});
|
|
@@ -26,7 +26,7 @@ export const makeHttpClientRequestHandler = (config) => Effect.gen(function* ()
|
|
|
26
26
|
const client = yield* HttpClient.HttpClient;
|
|
27
27
|
return HttpHandler.make({
|
|
28
28
|
handle: (request, handlerOptions) => Effect.gen(function* () {
|
|
29
|
-
const requestTimeoutInMs = Option.
|
|
29
|
+
const requestTimeoutInMs = Option.fromNullishOr(handlerOptions?.requestTimeout ?? config.requestTimeout).pipe(Option.map(Duration.millis), Option.getOrElse(() => Duration.infinity));
|
|
30
30
|
const url = makeUrl(request);
|
|
31
31
|
// Request constructor doesn't allow GET/HEAD request with body
|
|
32
32
|
// ref: https://github.com/whatwg/fetch/issues/551
|
|
@@ -35,9 +35,9 @@ export const makeHttpClientRequestHandler = (config) => Effect.gen(function* ()
|
|
|
35
35
|
: HttpBody.raw(request.body);
|
|
36
36
|
const fetch = HttpClientRequest.make(request.method);
|
|
37
37
|
const httpRequest = fetch(url, { body, headers: request.headers });
|
|
38
|
-
const response = yield* client.execute(httpRequest).pipe(Effect.flatMap((res) => tryToReadableStream(res.stream).pipe(Effect.catchTag("
|
|
38
|
+
const response = yield* client.execute(httpRequest).pipe(Effect.flatMap((res) => tryToReadableStream(res.stream).pipe(Effect.catchTag("HttpClientError", (error) => error.reason instanceof HttpClientError.EmptyBodyError ? res.arrayBuffer : Effect.fail(error)), Effect.map((body) => new HttpResponse({
|
|
39
39
|
headers: res.headers,
|
|
40
|
-
reason: (res.original ?? res).source.statusText, // changed since @effect/platform@0.79.0
|
|
40
|
+
// reason: (res.original ?? res).source.statusText, // changed since @effect/platform@0.79.0
|
|
41
41
|
statusCode: res.status,
|
|
42
42
|
body,
|
|
43
43
|
})))), Effect.orDie, Effect.timeout(requestTimeoutInMs));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpHandler.js","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":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QACtB,CAAC,CAAC;KACL,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effect-aws/http-handler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"description": "Effectful AWS HTTP handler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,29 +15,25 @@
|
|
|
15
15
|
},
|
|
16
16
|
"homepage": "https://floydspace.github.io/effect-aws/docs/http-handler",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@smithy/protocol-http": "^5.3.
|
|
19
|
-
"@smithy/querystring-builder": "^4.2.
|
|
20
|
-
"@smithy/types": "^4.
|
|
18
|
+
"@smithy/protocol-http": "^5.3.8",
|
|
19
|
+
"@smithy/querystring-builder": "^4.2.8",
|
|
20
|
+
"@smithy/types": "^4.11.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"
|
|
24
|
-
"effect": "
|
|
25
|
-
"@effect-aws/commons": "^0.3.1"
|
|
23
|
+
"effect": ">=4.0.0 <5.0.0",
|
|
24
|
+
"@effect-aws/commons": "^1.0.0-beta.0"
|
|
26
25
|
},
|
|
27
|
-
"main": "./dist/cjs/index.js",
|
|
28
26
|
"module": "./dist/esm/index.js",
|
|
29
27
|
"types": "./dist/dts/index.d.ts",
|
|
30
28
|
"exports": {
|
|
31
29
|
"./package.json": "./package.json",
|
|
32
30
|
".": {
|
|
33
31
|
"types": "./dist/dts/index.d.ts",
|
|
34
|
-
"import": "./dist/esm/index.js"
|
|
35
|
-
"default": "./dist/cjs/index.js"
|
|
32
|
+
"import": "./dist/esm/index.js"
|
|
36
33
|
},
|
|
37
34
|
"./HttpHandler": {
|
|
38
35
|
"types": "./dist/dts/HttpHandler.d.ts",
|
|
39
|
-
"import": "./dist/esm/HttpHandler.js"
|
|
40
|
-
"default": "./dist/cjs/HttpHandler.js"
|
|
36
|
+
"import": "./dist/esm/HttpHandler.js"
|
|
41
37
|
}
|
|
42
38
|
},
|
|
43
39
|
"typesVersions": {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { HttpHandlerOptions } from "@effect-aws/commons";
|
|
2
2
|
import { HttpHandler } from "@effect-aws/commons";
|
|
3
|
-
import type { HttpMethod } from "@effect/platform";
|
|
4
|
-
import { HttpBody, HttpClient, HttpClientRequest } from "@effect/platform";
|
|
5
3
|
import type { HttpRequest } from "@smithy/protocol-http";
|
|
6
4
|
import { HttpResponse } from "@smithy/protocol-http";
|
|
7
5
|
import { buildQueryString } from "@smithy/querystring-builder";
|
|
8
6
|
import type { RequestHandlerOutput } from "@smithy/types";
|
|
9
7
|
import type { Cause, Scope } from "effect";
|
|
10
8
|
import { Duration, Effect, Option, Sink, Stream } from "effect";
|
|
9
|
+
import type { HttpMethod } from "effect/unstable/http";
|
|
10
|
+
import { HttpBody, HttpClient, HttpClientError, HttpClientRequest } from "effect/unstable/http";
|
|
11
11
|
|
|
12
|
-
declare module "
|
|
12
|
+
declare module "effect/unstable/http" {
|
|
13
13
|
interface HttpClientResponse {
|
|
14
14
|
/**
|
|
15
15
|
* @private
|
|
@@ -63,11 +63,11 @@ export const makeHttpClientRequestHandler = (config: HttpHandlerOptions) =>
|
|
|
63
63
|
handlerOptions?: HttpHandlerOptions,
|
|
64
64
|
): Effect.Effect<
|
|
65
65
|
RequestHandlerOutput<HttpResponse>,
|
|
66
|
-
Cause.
|
|
66
|
+
Cause.TimeoutError,
|
|
67
67
|
Scope.Scope
|
|
68
68
|
> =>
|
|
69
69
|
Effect.gen(function*() {
|
|
70
|
-
const requestTimeoutInMs = Option.
|
|
70
|
+
const requestTimeoutInMs = Option.fromNullishOr(handlerOptions?.requestTimeout ?? config.requestTimeout).pipe(
|
|
71
71
|
Option.map(Duration.millis),
|
|
72
72
|
Option.getOrElse(() => Duration.infinity),
|
|
73
73
|
);
|
|
@@ -86,13 +86,14 @@ export const makeHttpClientRequestHandler = (config: HttpHandlerOptions) =>
|
|
|
86
86
|
Effect.flatMap((res) =>
|
|
87
87
|
tryToReadableStream(res.stream).pipe(
|
|
88
88
|
Effect.catchTag(
|
|
89
|
-
"
|
|
90
|
-
(error) =>
|
|
89
|
+
"HttpClientError",
|
|
90
|
+
(error) =>
|
|
91
|
+
error.reason instanceof HttpClientError.EmptyBodyError ? res.arrayBuffer : Effect.fail(error),
|
|
91
92
|
),
|
|
92
93
|
Effect.map((body) =>
|
|
93
94
|
new HttpResponse({
|
|
94
95
|
headers: res.headers,
|
|
95
|
-
reason: (res.original ?? res).source.statusText, // changed since @effect/platform@0.79.0
|
|
96
|
+
// reason: (res.original ?? res).source.statusText, // changed since @effect/platform@0.79.0
|
|
96
97
|
statusCode: res.status,
|
|
97
98
|
body,
|
|
98
99
|
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @since 0.1.0
|
|
3
|
-
*/
|
|
4
|
-
import type { HttpHandlerOptions } from "@effect-aws/commons";
|
|
5
|
-
import { HttpHandler } from "@effect-aws/commons";
|
|
6
|
-
import { Layer } from "effect";
|
|
7
|
-
/**
|
|
8
|
-
* @since 0.1.0
|
|
9
|
-
* @category layers
|
|
10
|
-
*/
|
|
11
|
-
export declare const layer: (config?: HttpHandlerOptions) => Layer.Layer<HttpHandler.RequestHandler, never, import("@effect/platform/HttpClient").HttpClient>;
|
|
12
|
-
//# sourceMappingURL=HttpHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpHandler.d.ts","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAG/B;;;GAGG;AACH,eAAO,MAAM,KAAK,YAAa,kBAAkB,qGACqC,CAAC"}
|
package/dist/cjs/HttpHandler.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.layer = void 0;
|
|
4
|
-
const commons_1 = require("@effect-aws/commons");
|
|
5
|
-
const effect_1 = require("effect");
|
|
6
|
-
const httpHandler_js_1 = require("./internal/httpHandler.js");
|
|
7
|
-
/**
|
|
8
|
-
* @since 0.1.0
|
|
9
|
-
* @category layers
|
|
10
|
-
*/
|
|
11
|
-
const layer = (config) => effect_1.Layer.effect(commons_1.HttpHandler.RequestHandler, (0, httpHandler_js_1.makeHttpClientRequestHandler)(config ?? {}));
|
|
12
|
-
exports.layer = layer;
|
|
13
|
-
//# sourceMappingURL=HttpHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpHandler.js","sourceRoot":"","sources":["../../src/HttpHandler.ts"],"names":[],"mappings":";;;AAIA,iDAAkD;AAClD,mCAA+B;AAC/B,8DAAyE;AAEzE;;;GAGG;AACI,MAAM,KAAK,GAAG,CAAC,MAA2B,EAAE,EAAE,CACnD,cAAK,CAAC,MAAM,CAAC,qBAAW,CAAC,cAAc,EAAE,IAAA,6CAA4B,EAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;AAD1E,QAAA,KAAK,SACqE"}
|
package/dist/cjs/index.d.ts
DELETED
package/dist/cjs/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.HttpHandler = void 0;
|
|
27
|
-
/**
|
|
28
|
-
* @since 0.1.0
|
|
29
|
-
*/
|
|
30
|
-
exports.HttpHandler = __importStar(require("./HttpHandler.js"));
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,gEAAgD"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare module "@effect/platform/HttpClientResponse" {
|
|
2
|
-
interface HttpClientResponse {
|
|
3
|
-
/**
|
|
4
|
-
* @private
|
|
5
|
-
*/
|
|
6
|
-
source: globalThis.Response;
|
|
7
|
-
/**
|
|
8
|
-
* @private
|
|
9
|
-
* @since 0.79.0
|
|
10
|
-
*/
|
|
11
|
-
original?: HttpClientResponse;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export {};
|
|
15
|
-
//# sourceMappingURL=httpHandler.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"httpHandler.d.ts","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":"AAWA,OAAO,QAAQ,qCAAqC,CAAC;IACnD,UAAU,kBAAkB;QAC1B;;WAEG;QACH,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC;QAE5B;;;WAGG;QACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;KAC/B;CACF"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeHttpClientRequestHandler = void 0;
|
|
4
|
-
const commons_1 = require("@effect-aws/commons");
|
|
5
|
-
const platform_1 = require("@effect/platform");
|
|
6
|
-
const protocol_http_1 = require("@smithy/protocol-http");
|
|
7
|
-
const querystring_builder_1 = require("@smithy/querystring-builder");
|
|
8
|
-
const effect_1 = require("effect");
|
|
9
|
-
const makeUrl = (request) => {
|
|
10
|
-
let path = request.path;
|
|
11
|
-
const queryString = (0, querystring_builder_1.buildQueryString)(request.query || {});
|
|
12
|
-
if (queryString) {
|
|
13
|
-
path += `?${queryString}`;
|
|
14
|
-
}
|
|
15
|
-
if (request.fragment) {
|
|
16
|
-
path += `#${request.fragment}`;
|
|
17
|
-
}
|
|
18
|
-
let auth = "";
|
|
19
|
-
if (request.username != null || request.password != null) {
|
|
20
|
-
const username = request.username ?? "";
|
|
21
|
-
const password = request.password ?? "";
|
|
22
|
-
auth = `${username}:${password}@`;
|
|
23
|
-
}
|
|
24
|
-
return `${request.protocol}//${auth}${request.hostname}${request.port ? `:${request.port}` : ""}${path}`;
|
|
25
|
-
};
|
|
26
|
-
const tryToReadableStream = (stream) => effect_1.Stream.peel(stream, effect_1.Sink.head()).pipe(effect_1.Effect.map(([head, tailStream]) => effect_1.Option.isNone(head) ? effect_1.Stream.empty : effect_1.Stream.merge(effect_1.Stream.make(head.value), tailStream)), effect_1.Effect.flatMap(effect_1.Stream.toReadableStreamEffect()));
|
|
27
|
-
/** @internal */
|
|
28
|
-
const makeHttpClientRequestHandler = (config) => effect_1.Effect.gen(function* () {
|
|
29
|
-
const client = yield* platform_1.HttpClient.HttpClient;
|
|
30
|
-
return commons_1.HttpHandler.make({
|
|
31
|
-
handle: (request, handlerOptions) => effect_1.Effect.gen(function* () {
|
|
32
|
-
const requestTimeoutInMs = effect_1.Option.fromNullable(handlerOptions?.requestTimeout ?? config.requestTimeout).pipe(effect_1.Option.map(effect_1.Duration.millis), effect_1.Option.getOrElse(() => effect_1.Duration.infinity));
|
|
33
|
-
const url = makeUrl(request);
|
|
34
|
-
// Request constructor doesn't allow GET/HEAD request with body
|
|
35
|
-
// ref: https://github.com/whatwg/fetch/issues/551
|
|
36
|
-
const body = request.method === "GET" || request.method === "HEAD"
|
|
37
|
-
? platform_1.HttpBody.empty
|
|
38
|
-
: platform_1.HttpBody.raw(request.body);
|
|
39
|
-
const fetch = platform_1.HttpClientRequest.make(request.method);
|
|
40
|
-
const httpRequest = fetch(url, { body, headers: request.headers });
|
|
41
|
-
const response = yield* client.execute(httpRequest).pipe(effect_1.Effect.flatMap((res) => tryToReadableStream(res.stream).pipe(effect_1.Effect.catchTag("ResponseError", (error) => error.reason === "EmptyBody" ? res.arrayBuffer : effect_1.Effect.fail(error)), effect_1.Effect.map((body) => new protocol_http_1.HttpResponse({
|
|
42
|
-
headers: res.headers,
|
|
43
|
-
reason: (res.original ?? res).source.statusText, // changed since @effect/platform@0.79.0
|
|
44
|
-
statusCode: res.status,
|
|
45
|
-
body,
|
|
46
|
-
})))), effect_1.Effect.orDie, effect_1.Effect.timeout(requestTimeoutInMs));
|
|
47
|
-
return { response };
|
|
48
|
-
}),
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
exports.makeHttpClientRequestHandler = makeHttpClientRequestHandler;
|
|
52
|
-
//# sourceMappingURL=httpHandler.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"httpHandler.js","sourceRoot":"","sources":["../../../src/internal/httpHandler.ts"],"names":[],"mappings":";;;AACA,iDAAkD;AAElD,+CAA2E;AAE3E,yDAAqD;AACrD,qEAA+D;AAG/D,mCAAgE;AAiBhE,MAAM,OAAO,GAAG,CAAC,OAAoB,EAAU,EAAE;IAC/C,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IACxB,MAAM,WAAW,GAAG,IAAA,sCAAgB,EAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC1D,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,IAAI,IAAI,WAAW,EAAE,CAAC;IAC5B,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,IAAI,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;QACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;QACxC,IAAI,GAAG,GAAG,QAAQ,IAAI,QAAQ,GAAG,CAAC;IACpC,CAAC;IAED,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IA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