Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update undici #268

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/agent.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as httpie from "../dist/index.js";
// import * as httpie from "@myunisoft/httpie";

const yoda = {
customPath: "yoda",
domains: new Set([
"yoda.myunisoft.fr"
"app.dev.myunisoft.tech"
]),
agent: new httpie.Agent({
connections: 500
Expand All @@ -13,9 +12,9 @@ const yoda = {
// Work by reading the NODE_ENV var.
prod: "",
preprod: "",
dev: "https://yoda.myunisoft.fr:1407"
dev: "https://app.dev.myunisoft.tech"
};
httpie.agents.add(yoda);

const { data } = await httpie.get("/yoda/api/v1/ipa/healthz");
const { data } = await httpie.get("/api/v1/ipa/healthz");
console.log(data);
106 changes: 53 additions & 53 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
{
"name": "@myunisoft/httpie",
"version": "4.0.0",
"description": "MyUnisoft Node.js HTTP client that use Undici client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MyUnisoft/httpie.git"
},
"engines": {
"node": ">=18"
},
"keywords": [],
"files": [
"dist"
],
"publishConfig": {
"@myunisoft:registry": "https://registry.npmjs.org/"
},
"author": "GENTILHOMME Thomas <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/MyUnisoft/httpie/issues"
},
"homepage": "https://github.com/MyUnisoft/httpie#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.9.0",
"@types/content-type": "^1.1.8",
"@types/jest": "^29.5.11",
"@types/lru-cache": "^7.10.10",
"@types/node": "^20.10.4",
"@types/statuses": "^2.0.4",
"dotenv": "^16.3.1",
"fastify": "^4.24.3",
"jest": "^29.7.0",
"p-ratelimit": "^1.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@openally/result": "^1.2.0",
"content-type": "^1.0.5",
"lru-cache": "^10.1.0",
"statuses": "^2.0.1",
"undici": "^6.0.1"
}
}
{
"name": "@myunisoft/httpie",
"version": "4.0.0",
"description": "MyUnisoft Node.js HTTP client that use Undici client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"prepublishOnly": "npm run build",
"test": "jest"
},
"repository": {
"type": "git",
"url": "git+https://github.com/MyUnisoft/httpie.git"
},
"engines": {
"node": ">=18"
},
"keywords": [],
"files": [
"dist"
],
"publishConfig": {
"@myunisoft:registry": "https://registry.npmjs.org/"
},
"author": "GENTILHOMME Thomas <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/MyUnisoft/httpie/issues"
},
"homepage": "https://github.com/MyUnisoft/httpie#readme",
"devDependencies": {
"@nodesecure/eslint-config": "^1.9.0",
"@types/content-type": "^1.1.8",
"@types/jest": "^29.5.11",
"@types/lru-cache": "^7.10.10",
"@types/node": "^20.10.4",
"@types/statuses": "^2.0.4",
"dotenv": "^16.3.1",
"fastify": "^4.24.3",
"jest": "^29.7.0",
"p-ratelimit": "^1.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@openally/result": "^1.2.0",
"content-type": "^1.0.5",
"lru-cache": "^10.1.0",
"statuses": "^2.0.1",
"undici": "^7.2.0"
}
}
4 changes: 2 additions & 2 deletions src/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const agents: Set<CustomHttpAgent> = new Set();
*
* @example
* const URI = computeAgentPath("/windev/ws_monitoring", windev);
* assert.strictEqual(URI, "https://ws-dev.myunisoft.fr/ws_monitoring");
* assert.strictEqual(URI, "https://ws.dev.myunisoft.tech/ws_monitoring");
*/
export function isAgentPathMatchingURI(uri: string, agent: CustomHttpAgent): URL | null {
// Note: we want to match both '/path/xxx...' and 'path/xxx...'
Expand Down Expand Up @@ -78,7 +78,7 @@ export function computeURIOnAllAgents(uri: string): computedUrlAndAgent {
* @see https://nodejs.org/api/url.html#url_url_hostname
*
* @example
* detectAgentFromURI("https://ws-dev.myunisoft.fr/ws_monitoring"); // windev agent
* detectAgentFromURI("https://ws.dev.myunisoft.tech/ws_monitoring"); // windev agent
* detectAgentFromURI("https://www.google.fr/"); // null
*/
export function detectAgentFromURI(uri: URL): CustomHttpAgent | null {
Expand Down
2 changes: 1 addition & 1 deletion src/class/undiciResponseHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class HttpieResponseHandler {
encodingHeader.reverse() :
encodingHeader.split(",").reverse();

let decompressedBuffer = Buffer.from(buffer);
let decompressedBuffer: Buffer = Buffer.from(buffer);
for (const rawEncoding of encodings) {
const encoding = rawEncoding.trim() as TypeOfDecompression;
const strategy = kDecompress[encoding];
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Headers,
HeadersInit,
FormData,
File,
BodyInit,
BodyMixin,
MockAgent,
Expand Down Expand Up @@ -36,7 +35,6 @@ export {
Headers,
HeadersInit,
FormData,
File,
BodyInit,
BodyMixin,
MockAgent,
Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface RequestResponse<T> {
* @see https://github.com/nodejs/undici
*
* @example
* const { statusCode, data } = await request("GET", "https://ws-dev.myunisoft.fr/ws_monitoring");
* const { statusCode, data } = await request("GET", "https://ws.dev.myunisoft.tech/ws_monitoring");
* console.log(statusCode, data); // 200 "true"
*/
export async function request<T>(
Expand Down
4 changes: 0 additions & 4 deletions test/__snapshots__/request.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ exports[`http.get should throw a 404 Not Found error because the path is not kno
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.56 (Debian) Server at ws-dev.myunisoft.fr Port 443</address>
</body></html>
"
`;
Expand All @@ -20,8 +18,6 @@ exports[`http.safeGet should throw a 404 Not Found error because the path is not
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.56 (Debian) Server at ws-dev.myunisoft.fr Port 443</address>
</body></html>
"
`;
4 changes: 2 additions & 2 deletions test/agents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { windev } from "./helpers";
import * as Agents from "../src/agents";

// CONSTANTS
const kWindevMonitoringURL = "https://ws-dev.myunisoft.fr/ws_monitoring";
const kWindevMonitoringURL = "https://ws.dev.myunisoft.tech/ws_monitoring";

describe("agents", () => {
it("should be an Array of CustomHttpAgent and must remain extensible", () => {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("computeURIOnAllAgents", () => {

describe("detectAgentFromURI", () => {
it("should detect windev agent with URI hostname", () => {
const returnedAgent = Agents.detectAgentFromURI(new URL("https://ws-dev.myunisoft.fr"));
const returnedAgent = Agents.detectAgentFromURI(new URL("https://ws.dev.myunisoft.tech"));

expect(returnedAgent).toStrictEqual(windev);
});
Expand Down
8 changes: 4 additions & 4 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { CustomHttpAgent, agents } from "../src/agents";
const windev: CustomHttpAgent = {
customPath: "windev",
domains: new Set([
"ws-dev.myunisoft.fr"
"ws.dev.myunisoft.tech"
]),
agent: new undici.Agent({
connections: 500
}),
prod: "https://ws-dev.myunisoft.fr",
preprod: "https://ws-dev.myunisoft.fr",
dev: "https://ws-dev.myunisoft.fr"
prod: "https://ws.dev.myunisoft.tech",
preprod: "https://ws.sta.myunisoft.tech",
dev: "https://ws.dev.myunisoft.tech"
};
agents.add(windev);

Expand Down
3 changes: 2 additions & 1 deletion test/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("http.get", () => {
});

it("should GET json response from node.js health endpoint", async() => {
const { data } = await get<any>("https://yoda.myunisoft.fr:1407/api/v1/ipa/healthz");
const { data } = await get<any>("https://app.dev.myunisoft.tech/api/v1/ipa/healthz");

expect(Object.keys(data).sort()).toMatchObject([
"status", "version", "description", "checks"
Expand Down Expand Up @@ -182,6 +182,7 @@ describe("http.safeGet", () => {

if (result.err) {
const error = result.val;
console.log(error);

expect(error.name).toStrictEqual("HttpieOnHttpError");
expect(error.statusCode).toStrictEqual(404);
Expand Down
Loading