Skip to content

Commit 2bb92a4

Browse files
authored
(fix) Use the initial user agent header within the agent api call (#15)
* use the current request user agent * update the alpha release * update local dependency versions
1 parent 7357126 commit 2bb92a4

9 files changed

Lines changed: 91 additions & 25 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=for-the-badge)](LICENSE)
2-
[![GitHub license](https://img.shields.io/badge/install-MacOSX-blue.svg?style=for-the-badge&logo=apple)](https://github.com/dfinity/http-proxy/releases/download/0.0.1-alpha/ic-http-proxy-mac-universal-0.0.1-alpha.dmg)
3-
[![GitHub license](https://img.shields.io/badge/install-Windows-blue.svg?style=for-the-badge&logo=windows)](https://github.com/dfinity/http-proxy/releases/download/0.0.1-alpha/ic-http-proxy-win-x64-0.0.1-alpha.exe)
2+
[![GitHub license](https://img.shields.io/badge/install-MacOSX-blue.svg?style=for-the-badge&logo=apple)](https://github.com/dfinity/http-proxy/releases/download/0.0.2-alpha/ic-http-proxy-mac-universal-0.0.2-alpha.dmg)
3+
[![GitHub license](https://img.shields.io/badge/install-Windows-blue.svg?style=for-the-badge&logo=windows)](https://github.com/dfinity/http-proxy/releases/download/0.0.2-alpha/ic-http-proxy-win-x64-0.0.2-alpha.exe)
44

55
# IC HTTP Proxy
66
> This application is currently only a proof of concept implementation and should be used at your own risk.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dfinity/http-proxy",
3-
"version": "0.0.1-alpha",
3+
"version": "0.0.2-alpha",
44
"description": "HTTP Proxy to enable trustless access to the Internet Computer.",
55
"author": "Kepler Vital <kepler.vital@dfinity.org>",
66
"license": "Apache-2.0",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dfinity/http-proxy-core",
3-
"version": "0.0.1-alpha",
3+
"version": "0.0.2-alpha",
44
"description": "Gateway server to enable trustless access to the Internet Computer.",
55
"main": "built/main.js",
66
"types": "built/main.d.ts",

packages/daemon/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dfinity/http-proxy-daemon",
3-
"version": "0.0.1-alpha",
3+
"version": "0.0.2-alpha",
44
"description": "Daemon process to enable trustless access to the Internet Computer.",
55
"main": "built/main.js",
66
"types": "built/main.d.ts",
@@ -59,7 +59,7 @@
5959
"typescript": "^4.9.5"
6060
},
6161
"dependencies": {
62-
"@dfinity/http-proxy-core": "0.0.1-alpha",
62+
"@dfinity/http-proxy-core": "0.0.2-alpha",
6363
"http-proxy": "^1.18.1",
6464
"node-cache": "^5.1.2",
6565
"node-forge": "^1.3.1",

packages/server/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dfinity/http-proxy-server",
3-
"version": "0.0.1-alpha",
3+
"version": "0.0.2-alpha",
44
"description": "Gateway server to enable trustless access to the Internet Computer.",
55
"main": "built/main.js",
66
"types": "built/main.d.ts",
@@ -34,6 +34,7 @@
3434
"yarn": "~3"
3535
},
3636
"devDependencies": {
37+
"@types/isomorphic-fetch": "^0.0.36",
3738
"@types/node": "^18.14.0",
3839
"@types/node-forge": "^1.3.1",
3940
"@types/pako": "^2.0.0",
@@ -50,11 +51,12 @@
5051
"dependencies": {
5152
"@dfinity/agent": "^0.15.6",
5253
"@dfinity/candid": "^0.15.6",
53-
"@dfinity/http-proxy-core": "0.0.1-alpha",
54-
"@dfinity/http-proxy-daemon": "0.0.1-alpha",
54+
"@dfinity/http-proxy-core": "0.0.2-alpha",
55+
"@dfinity/http-proxy-daemon": "0.0.2-alpha",
5556
"@dfinity/principal": "^0.15.6",
5657
"@dfinity/response-verification": "^0.2.1",
5758
"http-proxy": "^1.18.1",
59+
"isomorphic-fetch": "^3.0.0",
5860
"node-cache": "^5.1.2",
5961
"node-forge": "^1.3.1",
6062
"pako": "^2.1.0",

packages/server/src/commons/configs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { EnvironmentConfiguration } from './typings';
33

44
const environment: EnvironmentConfiguration = {
55
platform: os.platform(),
6-
userAgent: 'ICHttpProxy/0.0.1',
6+
userAgent: 'ICHttpProxy/0.0.2-alpha',
77
certificate: {
88
storage: {
99
folder: 'certs',

packages/server/src/servers/icp/utils.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { Actor, ActorSubclass, HttpAgent, concat } from '@dfinity/agent';
2+
import { logger } from '@dfinity/http-proxy-core';
23
import { Principal } from '@dfinity/principal';
34
import {
45
getMaxVerificationVersion,
56
getMinVerificationVersion,
67
verifyRequestResponsePair,
78
} from '@dfinity/response-verification/nodejs/nodejs.js';
89
import { IncomingMessage } from 'http';
10+
import fetch from 'isomorphic-fetch';
911
import { inflate, ungzip } from 'pako';
12+
import { environment } from '~src/commons';
1013
import { idlFactory } from '~src/commons/http-interface/canister_http_interface';
1114
import {
1215
HttpRequest,
@@ -22,17 +25,35 @@ import {
2225
HTTPMethods,
2326
HttpResponse,
2427
} from './typings';
25-
import { logger } from '@dfinity/http-proxy-core';
2628

2729
export const maxCertTimeOffsetNs = BigInt.asUintN(64, BigInt(300_000_000_000));
2830
export const cacheHeaders = [HTTPHeaders.CacheControl.toString()];
2931

3032
export async function createAgentAndActor(
3133
gatewayUrl: URL,
3234
canisterId: Principal,
33-
fetchRootKey: boolean
35+
fetchRootKey: boolean,
36+
userAgent: string
3437
): Promise<[HttpAgent, ActorSubclass<_SERVICE>]> {
35-
const agent = new HttpAgent({ host: gatewayUrl.toString() });
38+
// agent-js currently does not allow changing the user agent of the request with the fetchOptions,
39+
// with this change the initial user agent will be mantained with the addition of the ic http proxy info
40+
const customFetch: typeof fetch = (
41+
input: RequestInfo | URL,
42+
opts?: RequestInit
43+
): Promise<Response> => {
44+
if (opts) {
45+
opts.headers = {
46+
...(opts.headers ?? {}),
47+
[HTTPHeaders.UserAgent]: userAgent,
48+
};
49+
}
50+
51+
return fetch(input, opts);
52+
};
53+
const agent = new HttpAgent({
54+
host: gatewayUrl.toString(),
55+
fetch: customFetch,
56+
});
3657
if (fetchRootKey) {
3758
await agent.fetchRootKey();
3859
}
@@ -257,10 +278,13 @@ export const fetchFromInternetComputer = async (
257278
const minAllowedVerificationVersion = getMinVerificationVersion();
258279
const desiredVerificationVersion = getMaxVerificationVersion();
259280

281+
const agentUserAgent =
282+
request.headers.get(HTTPHeaders.UserAgent) ?? environment.userAgent;
260283
const [agent, actor] = await createAgentAndActor(
261284
DEFAULT_GATEWAY,
262285
canister,
263-
shouldFetchRootKey
286+
shouldFetchRootKey,
287+
agentUserAgent
264288
);
265289
const result = await fetchAsset({
266290
agent,

packages/ui/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dfinity/http-proxy-ui",
3-
"version": "0.0.1-alpha",
3+
"version": "0.0.2-alpha",
44
"description": "Desktop interface to facilitate user interaction with the HTTP Proxy server.",
55
"main": "built/main.js",
66
"scripts": {
@@ -37,8 +37,8 @@
3737
},
3838
"homepage": "https://github.com/dfinity/http-proxy/tree/main/packages/ui#readme",
3939
"dependencies": {
40-
"@dfinity/http-proxy-core": "0.0.1-alpha",
41-
"@dfinity/http-proxy-server": "0.0.1-alpha"
40+
"@dfinity/http-proxy-core": "0.0.2-alpha",
41+
"@dfinity/http-proxy-server": "0.0.2-alpha"
4242
},
4343
"devDependencies": {
4444
"@types/node": "^18.14.0",

yarn.lock

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ __metadata:
113113
languageName: node
114114
linkType: hard
115115

116-
"@dfinity/http-proxy-core@0.0.1-alpha, @dfinity/http-proxy-core@workspace:packages/core":
116+
"@dfinity/http-proxy-core@0.0.2-alpha, @dfinity/http-proxy-core@workspace:packages/core":
117117
version: 0.0.0-use.local
118118
resolution: "@dfinity/http-proxy-core@workspace:packages/core"
119119
dependencies:
@@ -138,11 +138,11 @@ __metadata:
138138
languageName: unknown
139139
linkType: soft
140140

141-
"@dfinity/http-proxy-daemon@0.0.1-alpha, @dfinity/http-proxy-daemon@workspace:packages/daemon":
141+
"@dfinity/http-proxy-daemon@0.0.2-alpha, @dfinity/http-proxy-daemon@workspace:packages/daemon":
142142
version: 0.0.0-use.local
143143
resolution: "@dfinity/http-proxy-daemon@workspace:packages/daemon"
144144
dependencies:
145-
"@dfinity/http-proxy-core": 0.0.1-alpha
145+
"@dfinity/http-proxy-core": 0.0.2-alpha
146146
"@types/node": ^18.14.0
147147
"@types/node-forge": ^1.3.1
148148
"@types/pako": ^2.0.0
@@ -166,16 +166,17 @@ __metadata:
166166
languageName: unknown
167167
linkType: soft
168168

169-
"@dfinity/http-proxy-server@0.0.1-alpha, @dfinity/http-proxy-server@workspace:packages/server":
169+
"@dfinity/http-proxy-server@0.0.2-alpha, @dfinity/http-proxy-server@workspace:packages/server":
170170
version: 0.0.0-use.local
171171
resolution: "@dfinity/http-proxy-server@workspace:packages/server"
172172
dependencies:
173173
"@dfinity/agent": ^0.15.6
174174
"@dfinity/candid": ^0.15.6
175-
"@dfinity/http-proxy-core": 0.0.1-alpha
176-
"@dfinity/http-proxy-daemon": 0.0.1-alpha
175+
"@dfinity/http-proxy-core": 0.0.2-alpha
176+
"@dfinity/http-proxy-daemon": 0.0.2-alpha
177177
"@dfinity/principal": ^0.15.6
178178
"@dfinity/response-verification": ^0.2.1
179+
"@types/isomorphic-fetch": ^0.0.36
179180
"@types/node": ^18.14.0
180181
"@types/node-forge": ^1.3.1
181182
"@types/pako": ^2.0.0
@@ -185,6 +186,7 @@ __metadata:
185186
eslint-config-prettier: ^8.7.0
186187
eslint-plugin-prettier: ^4.2.1
187188
http-proxy: ^1.18.1
189+
isomorphic-fetch: ^3.0.0
188190
node-cache: ^5.1.2
189191
node-forge: ^1.3.1
190192
nodemon: ^2.0.20
@@ -200,8 +202,8 @@ __metadata:
200202
version: 0.0.0-use.local
201203
resolution: "@dfinity/http-proxy-ui@workspace:packages/ui"
202204
dependencies:
203-
"@dfinity/http-proxy-core": 0.0.1-alpha
204-
"@dfinity/http-proxy-server": 0.0.1-alpha
205+
"@dfinity/http-proxy-core": 0.0.2-alpha
206+
"@dfinity/http-proxy-server": 0.0.2-alpha
205207
"@types/node": ^18.14.0
206208
"@typescript-eslint/eslint-plugin": ^5.54.1
207209
"@typescript-eslint/parser": ^5.54.1
@@ -579,6 +581,13 @@ __metadata:
579581
languageName: node
580582
linkType: hard
581583

584+
"@types/isomorphic-fetch@npm:^0.0.36":
585+
version: 0.0.36
586+
resolution: "@types/isomorphic-fetch@npm:0.0.36"
587+
checksum: 1ffaa1c97a019b1f7a682e2ae31bd4cc3f324198b422c62cece51b42d2750e0dde0c4df2320a52874d6c6019ee4b00ca2e736010d34b206a82e63ef82ef85bbe
588+
languageName: node
589+
linkType: hard
590+
582591
"@types/json-schema@npm:^7.0.9":
583592
version: 7.0.11
584593
resolution: "@types/json-schema@npm:7.0.11"
@@ -2923,6 +2932,16 @@ __metadata:
29232932
languageName: node
29242933
linkType: hard
29252934

2935+
"isomorphic-fetch@npm:^3.0.0":
2936+
version: 3.0.0
2937+
resolution: "isomorphic-fetch@npm:3.0.0"
2938+
dependencies:
2939+
node-fetch: ^2.6.1
2940+
whatwg-fetch: ^3.4.1
2941+
checksum: e5ab79a56ce5af6ddd21265f59312ad9a4bc5a72cebc98b54797b42cb30441d5c5f8d17c5cd84a99e18101c8af6f90c081ecb8d12fd79e332be1778d58486d75
2942+
languageName: node
2943+
linkType: hard
2944+
29262945
"jake@npm:^10.8.5":
29272946
version: 10.8.5
29282947
resolution: "jake@npm:10.8.5"
@@ -3439,6 +3458,20 @@ __metadata:
34393458
languageName: node
34403459
linkType: hard
34413460

3461+
"node-fetch@npm:^2.6.1":
3462+
version: 2.6.11
3463+
resolution: "node-fetch@npm:2.6.11"
3464+
dependencies:
3465+
whatwg-url: ^5.0.0
3466+
peerDependencies:
3467+
encoding: ^0.1.0
3468+
peerDependenciesMeta:
3469+
encoding:
3470+
optional: true
3471+
checksum: 249d0666a9497553384d46b5ab296ba223521ac88fed4d8a17d6ee6c2efb0fc890f3e8091cafe7f9fba8151a5b8d925db2671543b3409a56c3cd522b468b47b3
3472+
languageName: node
3473+
linkType: hard
3474+
34423475
"node-fetch@npm:^2.6.6":
34433476
version: 2.6.9
34443477
resolution: "node-fetch@npm:2.6.9"
@@ -4880,6 +4913,13 @@ __metadata:
48804913
languageName: node
48814914
linkType: hard
48824915

4916+
"whatwg-fetch@npm:^3.4.1":
4917+
version: 3.6.2
4918+
resolution: "whatwg-fetch@npm:3.6.2"
4919+
checksum: ee976b7249e7791edb0d0a62cd806b29006ad7ec3a3d89145921ad8c00a3a67e4be8f3fb3ec6bc7b58498724fd568d11aeeeea1f7827e7e1e5eae6c8a275afed
4920+
languageName: node
4921+
linkType: hard
4922+
48834923
"whatwg-url@npm:^5.0.0":
48844924
version: 5.0.0
48854925
resolution: "whatwg-url@npm:5.0.0"

0 commit comments

Comments
 (0)