Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/http-client",
"comment": "replace `node-fetch` with native `fetch` API",
"type": "minor"
}
],
"packageName": "@subsquid/http-client"
}
2 changes: 0 additions & 2 deletions util/http-client/esm.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions util/http-client/esm.js

This file was deleted.

12 changes: 5 additions & 7 deletions util/http-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@subsquid/http-client",
"version": "1.8.0",
"version": "2.0.0",
"description": "Small convenience layer on top of fetch",
"license": "GPL-3.0-or-later",
"repository": "git@github.com:subsquid/squid-sdk.git",
Expand All @@ -10,17 +10,15 @@
"main": "lib/index.js",
"files": [
"lib",
"src",
"esm.d.ts",
"esm.js"
"src"
],
"scripts": {
"build": "rm -rf lib && tsc"
"build": "rm -rf lib && tsc",
"test": "node --test lib/client.test.js"
},
"dependencies": {
"@subsquid/logger": "^1.5.0",
"@subsquid/util-internal": "^3.2.0",
"node-fetch": "^3.3.2"
"@subsquid/util-internal": "^3.2.0"
},
"devDependencies": {
"@types/node": "^18.18.14",
Expand Down
37 changes: 8 additions & 29 deletions util/http-client/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
import * as http from 'http'
import * as https from 'https'


export interface AgentProvider {
getNativeAgent(url: string): http.Agent
close?(): void
}


export const defaultAgentProvider: AgentProvider = {
getNativeAgent(url: string): http.Agent {
if (url.startsWith('https://')) {
return https.globalAgent
} else {
return http.globalAgent
}
}
}
export const defaultAgentProvider: AgentProvider = {}


/**
* @deprecated Built-in fetch manages keep-alive connections internally.
* Retained for backward compatibility.
*/
export class HttpAgent implements AgentProvider {
private http?: http.Agent
private https?: https.Agent

constructor(private options: https.AgentOptions) {}

getNativeAgent(url: string): http.Agent {
if (url.startsWith('https://')) {
return this.https || (this.https = new https.Agent(this.options))
} else {
return this.http || (this.http = new http.Agent(this.options))
}
}
constructor(_options?: Record<string, any>) {}

close() {
this.http?.destroy()
this.https?.destroy()
}
close() {}
}
Loading
Loading