@libp2p/http-utils 0.0.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.
@@ -0,0 +1,41 @@
1
+ import { getHeaders, isWebSocketUpgrade } from './index.js';
2
+ /**
3
+ * Extends the native Request class to be more flexible.
4
+ *
5
+ * - body - normally GET requests cannot have a body, but if the request is for
6
+ * a WebSocket upgrade, we need the body to turn into the socket
7
+ *
8
+ * Also firefox Web Workers remove the request body though weirdly the main
9
+ * thread doesn't.
10
+ *
11
+ * - headers - the global browser request removes certain headers like
12
+ * Authorization and Sec-WebSocket-Protocol but we need to preserve them
13
+ */
14
+ export class Request extends globalThis.Request {
15
+ constructor(input, init = {}) {
16
+ const method = init.method ?? 'GET';
17
+ const headers = getHeaders(init);
18
+ const body = init.body;
19
+ if (isWebSocketUpgrade(method, headers)) {
20
+ // temporarily override the method name since undici does not allow GET
21
+ // requests with bodies
22
+ init.method = 'UPGRADE';
23
+ }
24
+ super(input, init);
25
+ Object.defineProperties(this, {
26
+ body: {
27
+ value: body,
28
+ writable: false
29
+ },
30
+ method: {
31
+ value: method,
32
+ writable: false
33
+ },
34
+ headers: {
35
+ value: headers,
36
+ writable: false
37
+ }
38
+ });
39
+ }
40
+ }
41
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE3D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,OAAQ,SAAQ,UAAU,CAAC,OAAO;IAC7C,YAAa,KAAwB,EAAE,OAAoB,EAAE;QAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,KAAK,CAAA;QACnC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAChC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;QAEtB,IAAI,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;YACxC,uEAAuE;YACvE,uBAAuB;YACvB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;QACzB,CAAC;QAED,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAElB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;YAC5B,IAAI,EAAE;gBACJ,KAAK,EAAE,IAAI;gBACX,QAAQ,EAAE,KAAK;aAChB;YACD,MAAM,EAAE;gBACN,KAAK,EAAE,MAAM;gBACb,QAAQ,EAAE,KAAK;aAChB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,OAAO;gBACd,QAAQ,EAAE,KAAK;aAChB;SACF,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Extends the native Response class to be more flexible.
3
+ *
4
+ * - response headers - the fetch spec restricts access to certain headers that
5
+ * we need access to `set-cookie`, `Access-Control-*`, etc, and the native
6
+ * Response implementations remove them
7
+ *
8
+ * - status codes - we need to represent all possible HTTP status codes, not
9
+ * just those allowed by the fetch spec
10
+ */
11
+ export declare class Response extends globalThis.Response {
12
+ constructor(body: BodyInit | null, init?: ResponseInit);
13
+ }
14
+ //# sourceMappingURL=response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../src/response.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,qBAAa,QAAS,SAAQ,UAAU,CAAC,QAAQ;gBAClC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,GAAE,YAAiB;CAyB5D"}
@@ -0,0 +1,37 @@
1
+ import { STATUS_CODES } from './constants.js';
2
+ import { getHeaders } from './index.js';
3
+ /**
4
+ * Extends the native Response class to be more flexible.
5
+ *
6
+ * - response headers - the fetch spec restricts access to certain headers that
7
+ * we need access to `set-cookie`, `Access-Control-*`, etc, and the native
8
+ * Response implementations remove them
9
+ *
10
+ * - status codes - we need to represent all possible HTTP status codes, not
11
+ * just those allowed by the fetch spec
12
+ */
13
+ export class Response extends globalThis.Response {
14
+ constructor(body, init = {}) {
15
+ const headers = getHeaders(init);
16
+ const status = init.status ?? 200;
17
+ if (status < 200 || status > 599) {
18
+ init.status = 200;
19
+ }
20
+ super(body, init);
21
+ Object.defineProperties(this, {
22
+ status: {
23
+ value: status,
24
+ writable: false
25
+ },
26
+ statusText: {
27
+ value: STATUS_CODES[status],
28
+ writable: false
29
+ },
30
+ headers: {
31
+ value: headers,
32
+ writable: false
33
+ }
34
+ });
35
+ }
36
+ }
37
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,OAAO,QAAS,SAAQ,UAAU,CAAC,QAAQ;IAC/C,YAAa,IAAqB,EAAE,OAAqB,EAAE;QACzD,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAA;QAEjC,IAAI,MAAM,GAAG,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM,GAAG,GAAG,CAAA;QACnB,CAAC;QAED,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAEjB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;YAC5B,MAAM,EAAE;gBACN,KAAK,EAAE,MAAM;gBACb,QAAQ,EAAE,KAAK;aAChB;YACD,UAAU,EAAE;gBACV,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC;gBAC3B,QAAQ,EAAE,KAAK;aAChB;YACD,OAAO,EAAE;gBACP,KAAK,EAAE,OAAO;gBACd,QAAQ,EAAE,KAAK;aAChB;SACF,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ import type { Connection, Stream } from '@libp2p/interface';
2
+ import type { Socket } from 'node:net';
3
+ export declare function streamToSocket(stream: Stream, connection: Connection): Socket;
4
+ //# sourceMappingURL=stream-to-socket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-to-socket.d.ts","sourceRoot":"","sources":["../../src/stream-to-socket.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAoD,MAAM,UAAU,CAAA;AAkMxF,wBAAgB,cAAc,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,MAAM,CAE9E"}
@@ -0,0 +1,155 @@
1
+ import { Duplex } from 'node:stream';
2
+ import { byteStream } from 'it-byte-stream';
3
+ const MAX_TIMEOUT = 2_147_483_647;
4
+ class Libp2pSocket extends Duplex {
5
+ autoSelectFamilyAttemptedAddresses = [];
6
+ connecting = false;
7
+ pending = false;
8
+ remoteAddress;
9
+ bytesRead;
10
+ bytesWritten;
11
+ timeout = MAX_TIMEOUT;
12
+ allowHalfOpen;
13
+ stream;
14
+ constructor(stream, connection) {
15
+ const bytes = byteStream(stream);
16
+ super({
17
+ write: (chunk, encoding, cb) => {
18
+ this.stream.log('write %d bytes', chunk.byteLength);
19
+ this.bytesWritten += chunk.byteLength;
20
+ bytes.write(chunk)
21
+ .then(() => {
22
+ cb();
23
+ }, err => {
24
+ cb(err);
25
+ });
26
+ },
27
+ read: (size) => {
28
+ this.stream.log('asked to read %d bytes', size);
29
+ void Promise.resolve().then(async () => {
30
+ try {
31
+ while (true) {
32
+ const chunk = await bytes.read({
33
+ signal: AbortSignal.timeout(this.timeout)
34
+ });
35
+ if (chunk == null) {
36
+ this.stream.log('socket readable end closed');
37
+ this.push(null);
38
+ return;
39
+ }
40
+ this.bytesRead += chunk.byteLength;
41
+ this.stream.log('socket read %d bytes', chunk.byteLength);
42
+ const more = this.push(chunk.subarray());
43
+ if (!more) {
44
+ break;
45
+ }
46
+ }
47
+ }
48
+ catch (err) {
49
+ this.destroy(err);
50
+ }
51
+ });
52
+ },
53
+ destroy: (err, cb) => {
54
+ this.stream.log('destroy with %d bytes buffered - %e', this.bufferSize, err);
55
+ if (err != null) {
56
+ bytes.unwrap().abort(err);
57
+ cb();
58
+ }
59
+ else {
60
+ bytes.unwrap().close()
61
+ .then(() => {
62
+ cb();
63
+ })
64
+ .catch(err => {
65
+ stream.abort(err);
66
+ cb(err);
67
+ });
68
+ }
69
+ },
70
+ final: (cb) => {
71
+ this.stream.log('final');
72
+ bytes.unwrap().closeWrite()
73
+ .then(() => {
74
+ cb();
75
+ })
76
+ .catch(err => {
77
+ bytes.unwrap().abort(err);
78
+ cb(err);
79
+ });
80
+ }
81
+ });
82
+ this.stream = stream;
83
+ this.remoteAddress = connection.remoteAddr.toString();
84
+ this.bytesRead = 0;
85
+ this.bytesWritten = 0;
86
+ this.allowHalfOpen = true;
87
+ }
88
+ get readyState() {
89
+ if (this.stream.status === 'closed') {
90
+ return 'closed';
91
+ }
92
+ if (this.stream.writeStatus === 'closed' || this.stream.writeStatus === 'closing') {
93
+ return 'readOnly';
94
+ }
95
+ if (this.stream.readStatus === 'closed' || this.stream.readStatus === 'closing') {
96
+ return 'writeOnly';
97
+ }
98
+ return 'open';
99
+ }
100
+ get bufferSize() {
101
+ return this.writableLength;
102
+ }
103
+ destroySoon() {
104
+ this.stream.log('destroySoon with %d bytes buffered', this.bufferSize);
105
+ this.destroy();
106
+ }
107
+ connect(...args) {
108
+ this.stream.log('connect %o', args);
109
+ return this;
110
+ }
111
+ setEncoding(encoding) {
112
+ this.stream.log('setEncoding %s', encoding);
113
+ return this;
114
+ }
115
+ resetAndDestroy() {
116
+ this.stream.log('resetAndDestroy');
117
+ this.stream.abort(new Error('Libp2pSocket.resetAndDestroy'));
118
+ return this;
119
+ }
120
+ setTimeout(timeout, callback) {
121
+ this.stream.log('setTimeout %d', timeout);
122
+ if (callback != null) {
123
+ this.addListener('timeout', callback);
124
+ }
125
+ this.timeout = timeout === 0 ? MAX_TIMEOUT : timeout;
126
+ return this;
127
+ }
128
+ setNoDelay(noDelay) {
129
+ this.stream.log('setNoDelay %b', noDelay);
130
+ return this;
131
+ }
132
+ setKeepAlive(enable, initialDelay) {
133
+ this.stream.log('setKeepAlive %b %d', enable, initialDelay);
134
+ return this;
135
+ }
136
+ address() {
137
+ this.stream.log('address');
138
+ return {};
139
+ }
140
+ unref() {
141
+ this.stream.log('unref');
142
+ return this;
143
+ }
144
+ ref() {
145
+ this.stream.log('ref');
146
+ return this;
147
+ }
148
+ write(chunk, encoding, cb) {
149
+ return super.write(chunk, encoding, cb);
150
+ }
151
+ }
152
+ export function streamToSocket(stream, connection) {
153
+ return new Libp2pSocket(stream, connection);
154
+ }
155
+ //# sourceMappingURL=stream-to-socket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-to-socket.js","sourceRoot":"","sources":["../../src/stream-to-socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAI3C,MAAM,WAAW,GAAG,aAAa,CAAA;AAEjC,MAAM,YAAa,SAAQ,MAAM;IACf,kCAAkC,GAAG,EAAE,CAAA;IACvC,UAAU,GAAG,KAAK,CAAA;IAClB,OAAO,GAAG,KAAK,CAAA;IACf,aAAa,CAAQ;IAC9B,SAAS,CAAQ;IACjB,YAAY,CAAQ;IACpB,OAAO,GAAG,WAAW,CAAA;IACrB,aAAa,CAAS;IAEZ,MAAM,CAAQ;IAE/B,YAAa,MAAc,EAAE,UAAsB;QACjD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,CAAA;QAEhC,KAAK,CAAC;YACJ,KAA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A;IACzC,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAE,MAAc,EAAE,UAAsB;IACpE,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAC7C,CAAC"}
@@ -0,0 +1,57 @@
1
+ {
2
+ "Middleware": "https://libp2p.github.io/js-libp2p-http/interfaces/_libp2p_http.index.Middleware.html",
3
+ ".:Middleware": "https://libp2p.github.io/js-libp2p-http/interfaces/_libp2p_http-utils.Middleware.html",
4
+ "MiddlewareOptions": "https://libp2p.github.io/js-libp2p-http/interfaces/_libp2p_http.index.MiddlewareOptions.html",
5
+ ".:MiddlewareOptions": "https://libp2p.github.io/js-libp2p-http/interfaces/_libp2p_http-utils.MiddlewareOptions.html",
6
+ "Request": "https://libp2p.github.io/js-libp2p-http/classes/_libp2p_http-utils.Request.html",
7
+ "Response": "https://libp2p.github.io/js-libp2p-http/classes/_libp2p_http-utils.Response.html",
8
+ "HeaderInfo": "https://libp2p.github.io/js-libp2p-http/interfaces/_libp2p_http-utils.HeaderInfo.html",
9
+ ".:HeaderInfo": "https://libp2p.github.io/js-libp2p-http/interfaces/_libp2p_http-utils.HeaderInfo.html",
10
+ "BAD_REQUEST": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.BAD_REQUEST.html",
11
+ ".:BAD_REQUEST": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.BAD_REQUEST.html",
12
+ "DNS_CODEC": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.DNS_CODEC.html",
13
+ "DNS_CODECS": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.DNS_CODECS.html",
14
+ "DNS4_CODEC": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.DNS4_CODEC.html",
15
+ "DNS6_CODEC": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.DNS6_CODEC.html",
16
+ "DNSADDR_CODEC": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.DNSADDR_CODEC.html",
17
+ "HTTP_CODEC": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.HTTP_CODEC.html",
18
+ "HTTP_PATH_CODEC": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.HTTP_PATH_CODEC.html",
19
+ "INTERNAL_SERVER_ERROR": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.INTERNAL_SERVER_ERROR.html",
20
+ ".:INTERNAL_SERVER_ERROR": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.INTERNAL_SERVER_ERROR.html",
21
+ "NOT_FOUND_RESPONSE": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.NOT_FOUND_RESPONSE.html",
22
+ ".:NOT_FOUND_RESPONSE": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.NOT_FOUND_RESPONSE.html",
23
+ "NOT_IMPLEMENTED_ERROR": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.NOT_IMPLEMENTED_ERROR.html",
24
+ ".:NOT_IMPLEMENTED_ERROR": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.NOT_IMPLEMENTED_ERROR.html",
25
+ "STATUS_CODES": "https://libp2p.github.io/js-libp2p-http/variables/_libp2p_http-utils.STATUS_CODES.html",
26
+ "getHeader": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getHeader.html",
27
+ ".:getHeader": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getHeader.html",
28
+ "getHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getHeaders.html",
29
+ ".:getHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getHeaders.html",
30
+ "getHost": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getHost.html",
31
+ ".:getHost": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getHost.html",
32
+ "getServerUpgradeHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getServerUpgradeHeaders.html",
33
+ ".:getServerUpgradeHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.getServerUpgradeHeaders.html",
34
+ "isWebSocketUpgrade": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.isWebSocketUpgrade.html",
35
+ ".:isWebSocketUpgrade": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.isWebSocketUpgrade.html",
36
+ "normalizeMethod": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.normalizeMethod.html",
37
+ ".:normalizeMethod": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.normalizeMethod.html",
38
+ "normalizeUrl": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.normalizeUrl.html",
39
+ ".:normalizeUrl": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.normalizeUrl.html",
40
+ "readHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.readHeaders.html",
41
+ ".:readHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.readHeaders.html",
42
+ "responseToStream": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.responseToStream.html",
43
+ ".:responseToStream": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.responseToStream.html",
44
+ "streamToRequest": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.streamToRequest.html",
45
+ ".:streamToRequest": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.streamToRequest.html",
46
+ "streamToSocket": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.streamToSocket.html",
47
+ "stripHTTPPath": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.stripHTTPPath.html",
48
+ ".:stripHTTPPath": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.stripHTTPPath.html",
49
+ "toResource": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.toResource.html",
50
+ ".:toResource": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.toResource.html",
51
+ "toUint8Array": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.toUint8Array.html",
52
+ ".:toUint8Array": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.toUint8Array.html",
53
+ "toURL": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.toURL.html",
54
+ ".:toURL": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.toURL.html",
55
+ "writeHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.writeHeaders.html",
56
+ ".:writeHeaders": "https://libp2p.github.io/js-libp2p-http/functions/_libp2p_http-utils.writeHeaders.html"
57
+ }
package/package.json ADDED
@@ -0,0 +1,163 @@
1
+ {
2
+ "name": "@libp2p/http-utils",
3
+ "version": "0.0.0",
4
+ "description": "Shared utils and common code for HTTP modules",
5
+ "license": "Apache-2.0 OR MIT",
6
+ "homepage": "https://github.com/libp2p/js-libp2p-http/tree/main/packages/http-utils#readme",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/libp2p/js-libp2p-http.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/libp2p/js-libp2p-http/issues"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "type": "module",
18
+ "types": "./dist/src/index.d.ts",
19
+ "files": [
20
+ "src",
21
+ "dist",
22
+ "!dist/test",
23
+ "!**/*.tsbuildinfo"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/src/index.d.ts",
28
+ "import": "./dist/src/index.js"
29
+ }
30
+ },
31
+ "release": {
32
+ "branches": [
33
+ "main"
34
+ ],
35
+ "plugins": [
36
+ [
37
+ "@semantic-release/commit-analyzer",
38
+ {
39
+ "preset": "conventionalcommits",
40
+ "releaseRules": [
41
+ {
42
+ "breaking": true,
43
+ "release": "major"
44
+ },
45
+ {
46
+ "revert": true,
47
+ "release": "patch"
48
+ },
49
+ {
50
+ "type": "feat",
51
+ "release": "minor"
52
+ },
53
+ {
54
+ "type": "fix",
55
+ "release": "patch"
56
+ },
57
+ {
58
+ "type": "docs",
59
+ "release": "patch"
60
+ },
61
+ {
62
+ "type": "test",
63
+ "release": "patch"
64
+ },
65
+ {
66
+ "type": "deps",
67
+ "release": "patch"
68
+ },
69
+ {
70
+ "scope": "no-release",
71
+ "release": false
72
+ }
73
+ ]
74
+ }
75
+ ],
76
+ [
77
+ "@semantic-release/release-notes-generator",
78
+ {
79
+ "preset": "conventionalcommits",
80
+ "presetConfig": {
81
+ "types": [
82
+ {
83
+ "type": "feat",
84
+ "section": "Features"
85
+ },
86
+ {
87
+ "type": "fix",
88
+ "section": "Bug Fixes"
89
+ },
90
+ {
91
+ "type": "chore",
92
+ "section": "Trivial Changes"
93
+ },
94
+ {
95
+ "type": "docs",
96
+ "section": "Documentation"
97
+ },
98
+ {
99
+ "type": "deps",
100
+ "section": "Dependencies"
101
+ },
102
+ {
103
+ "type": "test",
104
+ "section": "Tests"
105
+ }
106
+ ]
107
+ }
108
+ }
109
+ ],
110
+ "@semantic-release/changelog",
111
+ "@semantic-release/npm",
112
+ "@semantic-release/github",
113
+ [
114
+ "@semantic-release/git",
115
+ {
116
+ "assets": [
117
+ "CHANGELOG.md",
118
+ "package.json"
119
+ ]
120
+ }
121
+ ]
122
+ ]
123
+ },
124
+ "scripts": {
125
+ "build": "aegir build",
126
+ "clean": "aegir clean",
127
+ "lint": "aegir lint",
128
+ "test": "aegir test",
129
+ "test:chrome": "aegir test -t browser --cov",
130
+ "test:firefox": "aegir test -t browser --browser firefox --cov",
131
+ "test:node": "aegir test -t node --cov",
132
+ "test:electron-main": "aegir test -t electron-main",
133
+ "test:chrome-webworker": "aegir test -t webworker",
134
+ "test:webkit": "aegir test -t browser -- --browser webkit",
135
+ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
136
+ "dep-check": "aegir dep-check -i readable-stream",
137
+ "doc-check": "aegir doc-check",
138
+ "docs": "aegir docs",
139
+ "release": "aegir release"
140
+ },
141
+ "dependencies": {
142
+ "@achingbrain/http-parser-js": "^0.5.9",
143
+ "@libp2p/interface": "^2.10.2",
144
+ "@libp2p/peer-id": "^5.1.5",
145
+ "@multiformats/multiaddr": "^12.4.0",
146
+ "@multiformats/multiaddr-to-uri": "^11.0.0",
147
+ "@multiformats/uri-to-multiaddr": "^9.0.1",
148
+ "it-byte-stream": "^2.0.2",
149
+ "it-queueless-pushable": "^2.0.1",
150
+ "it-to-browser-readablestream": "^2.0.11",
151
+ "multiformats": "^13.3.6",
152
+ "readable-stream": "^4.7.0",
153
+ "uint8arraylist": "^2.4.8",
154
+ "uint8arrays": "^5.1.0"
155
+ },
156
+ "devDependencies": {
157
+ "aegir": "^47.0.16"
158
+ },
159
+ "browser": {
160
+ "node:stream": "readable-stream"
161
+ },
162
+ "sideEffects": false
163
+ }
@@ -0,0 +1,77 @@
1
+ export const HTTP_PATH_CODEC = 0x01e1
2
+ export const HTTP_CODEC = 0x01e0
3
+ export const DNS_CODEC = 0x35
4
+ export const DNS4_CODEC = 0x36
5
+ export const DNS6_CODEC = 0x37
6
+ export const DNSADDR_CODEC = 0x38
7
+ export const DNS_CODECS = [
8
+ DNS_CODEC,
9
+ DNS4_CODEC,
10
+ DNS6_CODEC,
11
+ DNSADDR_CODEC
12
+ ]
13
+ export const STATUS_CODES: Record<string, string> = {
14
+ 100: 'Continue', // RFC 7231 6.2.1
15
+ 101: 'Switching Protocols', // RFC 7231 6.2.2
16
+ 102: 'Processing', // RFC 2518 10.1 (obsoleted by RFC 4918)
17
+ 103: 'Early Hints', // RFC 8297 2
18
+ 200: 'OK', // RFC 7231 6.3.1
19
+ 201: 'Created', // RFC 7231 6.3.2
20
+ 202: 'Accepted', // RFC 7231 6.3.3
21
+ 203: 'Non-Authoritative Information', // RFC 7231 6.3.4
22
+ 204: 'No Content', // RFC 7231 6.3.5
23
+ 205: 'Reset Content', // RFC 7231 6.3.6
24
+ 206: 'Partial Content', // RFC 7233 4.1
25
+ 207: 'Multi-Status', // RFC 4918 11.1
26
+ 208: 'Already Reported', // RFC 5842 7.1
27
+ 226: 'IM Used', // RFC 3229 10.4.1
28
+ 300: 'Multiple Choices', // RFC 7231 6.4.1
29
+ 301: 'Moved Permanently', // RFC 7231 6.4.2
30
+ 302: 'Found', // RFC 7231 6.4.3
31
+ 303: 'See Other', // RFC 7231 6.4.4
32
+ 304: 'Not Modified', // RFC 7232 4.1
33
+ 305: 'Use Proxy', // RFC 7231 6.4.5
34
+ 307: 'Temporary Redirect', // RFC 7231 6.4.7
35
+ 308: 'Permanent Redirect', // RFC 7238 3
36
+ 400: 'Bad Request', // RFC 7231 6.5.1
37
+ 401: 'Unauthorized', // RFC 7235 3.1
38
+ 402: 'Payment Required', // RFC 7231 6.5.2
39
+ 403: 'Forbidden', // RFC 7231 6.5.3
40
+ 404: 'Not Found', // RFC 7231 6.5.4
41
+ 405: 'Method Not Allowed', // RFC 7231 6.5.5
42
+ 406: 'Not Acceptable', // RFC 7231 6.5.6
43
+ 407: 'Proxy Authentication Required', // RFC 7235 3.2
44
+ 408: 'Request Timeout', // RFC 7231 6.5.7
45
+ 409: 'Conflict', // RFC 7231 6.5.8
46
+ 410: 'Gone', // RFC 7231 6.5.9
47
+ 411: 'Length Required', // RFC 7231 6.5.10
48
+ 412: 'Precondition Failed', // RFC 7232 4.2
49
+ 413: 'Payload Too Large', // RFC 7231 6.5.11
50
+ 414: 'URI Too Long', // RFC 7231 6.5.12
51
+ 415: 'Unsupported Media Type', // RFC 7231 6.5.13
52
+ 416: 'Range Not Satisfiable', // RFC 7233 4.4
53
+ 417: 'Expectation Failed', // RFC 7231 6.5.14
54
+ 418: 'I\'m a Teapot', // RFC 7168 2.3.3
55
+ 421: 'Misdirected Request', // RFC 7540 9.1.2
56
+ 422: 'Unprocessable Entity', // RFC 4918 11.2
57
+ 423: 'Locked', // RFC 4918 11.3
58
+ 424: 'Failed Dependency', // RFC 4918 11.4
59
+ 425: 'Too Early', // RFC 8470 5.2
60
+ 426: 'Upgrade Required', // RFC 2817 and RFC 7231 6.5.15
61
+ 428: 'Precondition Required', // RFC 6585 3
62
+ 429: 'Too Many Requests', // RFC 6585 4
63
+ 431: 'Request Header Fields Too Large', // RFC 6585 5
64
+ 451: 'Unavailable For Legal Reasons', // RFC 7725 3
65
+ 500: 'Internal Server Error', // RFC 7231 6.6.1
66
+ 501: 'Not Implemented', // RFC 7231 6.6.2
67
+ 502: 'Bad Gateway', // RFC 7231 6.6.3
68
+ 503: 'Service Unavailable', // RFC 7231 6.6.4
69
+ 504: 'Gateway Timeout', // RFC 7231 6.6.5
70
+ 505: 'HTTP Version Not Supported', // RFC 7231 6.6.6
71
+ 506: 'Variant Also Negotiates', // RFC 2295 8.1
72
+ 507: 'Insufficient Storage', // RFC 4918 11.5
73
+ 508: 'Loop Detected', // RFC 5842 7.2
74
+ 509: 'Bandwidth Limit Exceeded',
75
+ 510: 'Not Extended', // RFC 2774 7
76
+ 511: 'Network Authentication Required' // RFC 6585 6
77
+ }