Skip to content

Commit 99faa97

Browse files
committed
WIP - migrating to the new http client
1 parent 0772a0c commit 99faa97

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

lib/resolver.content.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import { Boom, badGateway } from '@hapi/boom';
77
import { join, dirname } from 'path';
88
import { fileURLToPath } from 'url';
99
import fs from 'fs';
10+
import HttpClient from '@podium/http-client';
1011
import * as utils from './utils.js';
1112
import Response from './response.js';
12-
import HTTP from './http.js';
1313

1414
const currentDirectory = dirname(fileURLToPath(import.meta.url));
1515

@@ -24,7 +24,7 @@ const UA_STRING = `${pkg.name} ${pkg.version}`;
2424
/**
2525
* @typedef {object} PodletClientContentResolverOptions
2626
* @property {string} clientName
27-
* @property {import('./http.js').default} [http]
27+
* @property {import('@podium/http-client').default} [http]
2828
* @property {import('abslog').AbstractLoggerOptions} [logger]
2929
*/
3030

@@ -40,7 +40,11 @@ export default class PodletClientContentResolver {
4040
*/
4141
// @ts-expect-error Deliberate default empty options for better error messages
4242
constructor(options = {}) {
43-
this.#http = options.http || new HTTP();
43+
this.#http = options.http || new HttpClient({
44+
timeout: options.timeout,
45+
throwOn400: options.throwable,
46+
throwOn500: options.throwable,
47+
});
4448
const name = options.clientName;
4549
this.#log = abslog(options.logger);
4650
this.#metrics = new Metrics();
@@ -158,11 +162,17 @@ export default class PodletClientContentResolver {
158162
);
159163

160164
try {
165+
const url = new URL(uri)
161166
const {
162167
statusCode,
163168
headers: hdrs,
164169
body,
165-
} = await this.#http.request(uri, reqOptions);
170+
} = await this.#http.request({
171+
origin: url.origin,
172+
path: url.pathname,
173+
method: reqOptions.method,
174+
throwable: reqOptions.throwable
175+
});
166176

167177
// Remote responds but with an http error code
168178
const resError = statusCode >= 400;

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
"dependencies": {
3838
"@hapi/boom": "10.0.1",
3939
"@metrics/client": "2.5.2",
40+
"@podium/http-client": "1.0.1-beta.1",
4041
"@podium/schemas": "5.0.5",
4142
"@podium/utils": "5.0.7",
4243
"abslog": "2.4.4",
4344
"http-cache-semantics": "^4.0.3",
4445
"lodash.clonedeep": "^4.5.0",
46+
"opossum": "^8.3.0",
4547
"ttl-mem-cache": "4.1.0",
4648
"undici": "6.18.2"
4749
},

tests/resolver.content.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
PodletServer,
77
HttpServer,
88
} from '@podium/test-utils';
9+
import HttpClient from "@podium/http-client/lib/http-client.js";
910
import HttpOutgoing from '../lib/http-outgoing.js';
1011
import Content from '../lib/resolver.content.js';
1112

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"declaration": true,
1111
"skipLibCheck": true,
1212
"allowSyntheticDefaultImports": true,
13-
"outDir": "types"
13+
"outDir": "types",
1414
},
1515
"include": ["./lib/**/*.js"]
1616
}

0 commit comments

Comments
 (0)