@helia/verified-fetch 3.0.1 → 3.1.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.
- package/dist/index.min.js +57 -45
- package/dist/index.min.js.map +4 -4
- package/dist/src/plugins/plugin-handle-byte-range-context.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-byte-range-context.js +5 -0
- package/dist/src/plugins/plugin-handle-byte-range-context.js.map +1 -1
- package/dist/src/plugins/plugin-handle-car.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-car.js +53 -8
- package/dist/src/plugins/plugin-handle-car.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-cbor.js +3 -2
- package/dist/src/plugins/plugin-handle-dag-cbor.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts +1 -0
- package/dist/src/plugins/plugin-handle-dag-pb.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-dag-pb.js +63 -23
- package/dist/src/plugins/plugin-handle-dag-pb.js.map +1 -1
- package/dist/src/plugins/plugin-handle-dir-index-html.js +2 -2
- package/dist/src/plugins/plugin-handle-dir-index-html.js.map +1 -1
- package/dist/src/plugins/plugin-handle-ipns-record.js +2 -2
- package/dist/src/plugins/plugin-handle-ipns-record.js.map +1 -1
- package/dist/src/plugins/plugin-handle-json.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-json.js +2 -3
- package/dist/src/plugins/plugin-handle-json.js.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.d.ts.map +1 -1
- package/dist/src/plugins/plugin-handle-raw.js +6 -5
- package/dist/src/plugins/plugin-handle-raw.js.map +1 -1
- package/dist/src/plugins/plugin-handle-tar.js +2 -2
- package/dist/src/plugins/plugin-handle-tar.js.map +1 -1
- package/dist/src/utils/byte-range-context.d.ts +39 -16
- package/dist/src/utils/byte-range-context.d.ts.map +1 -1
- package/dist/src/utils/byte-range-context.js +305 -104
- package/dist/src/utils/byte-range-context.js.map +1 -1
- package/dist/src/utils/{set-content-type.d.ts → get-content-type.d.ts} +3 -4
- package/dist/src/utils/get-content-type.d.ts.map +1 -0
- package/dist/src/utils/{set-content-type.js → get-content-type.js} +3 -4
- package/dist/src/utils/get-content-type.js.map +1 -0
- package/dist/src/utils/parse-url-string.d.ts +1 -0
- package/dist/src/utils/parse-url-string.d.ts.map +1 -1
- package/dist/src/utils/parse-url-string.js.map +1 -1
- package/dist/src/utils/responses.d.ts.map +1 -1
- package/dist/src/utils/responses.js +16 -4
- package/dist/src/utils/responses.js.map +1 -1
- package/dist/src/verified-fetch.js +1 -1
- package/dist/src/verified-fetch.js.map +1 -1
- package/package.json +2 -2
- package/src/plugins/plugin-handle-byte-range-context.ts +6 -0
- package/src/plugins/plugin-handle-car.ts +59 -8
- package/src/plugins/plugin-handle-dag-cbor.ts +4 -3
- package/src/plugins/plugin-handle-dag-pb.ts +68 -24
- package/src/plugins/plugin-handle-dir-index-html.ts +2 -2
- package/src/plugins/plugin-handle-ipns-record.ts +2 -2
- package/src/plugins/plugin-handle-json.ts +2 -3
- package/src/plugins/plugin-handle-raw.ts +7 -5
- package/src/plugins/plugin-handle-tar.ts +2 -2
- package/src/utils/byte-range-context.ts +373 -103
- package/src/utils/{set-content-type.ts → get-content-type.ts} +4 -5
- package/src/utils/parse-url-string.ts +1 -0
- package/src/utils/responses.ts +17 -4
- package/src/verified-fetch.ts +1 -1
- package/dist/src/utils/set-content-type.d.ts.map +0 -1
- package/dist/src/utils/set-content-type.js.map +0 -1
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { SupportedBodyTypes } from '../types.js';
|
|
2
2
|
import type { ComponentLogger } from '@libp2p/interface';
|
|
3
|
+
interface RequestRange {
|
|
4
|
+
start: number | undefined;
|
|
5
|
+
end: number | undefined;
|
|
6
|
+
}
|
|
7
|
+
interface ByteRange extends RequestRange {
|
|
8
|
+
size: number | undefined;
|
|
9
|
+
}
|
|
3
10
|
export declare class ByteRangeContext {
|
|
4
11
|
private readonly headers?;
|
|
5
12
|
readonly isRangeRequest: boolean;
|
|
@@ -10,14 +17,24 @@ export declare class ByteRangeContext {
|
|
|
10
17
|
private _body;
|
|
11
18
|
private readonly rangeRequestHeader;
|
|
12
19
|
private readonly log;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
private
|
|
20
|
+
/**
|
|
21
|
+
* multiPartBoundary is required for multipart responses
|
|
22
|
+
*/
|
|
23
|
+
private readonly multiPartBoundary?;
|
|
24
|
+
private readonly requestRanges;
|
|
25
|
+
private byteRanges;
|
|
26
|
+
readonly isMultiRangeRequest: boolean;
|
|
27
|
+
private _isValidRangeRequest;
|
|
18
28
|
constructor(logger: ComponentLogger, headers?: HeadersInit | undefined);
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
getByteRanges(): ByteRange[];
|
|
30
|
+
/**
|
|
31
|
+
* You can pass a function when you need to support multi-range requests but have your own slicing logic, such as in the case of dag-pb/unixfs.
|
|
32
|
+
*
|
|
33
|
+
* @param bodyOrProvider - A supported body type or a function that returns a supported body type.
|
|
34
|
+
* @param contentType - The content type of the body.
|
|
35
|
+
*/
|
|
36
|
+
setBody(bodyOrProvider: SupportedBodyTypes | ((range: ByteRange) => AsyncGenerator<Uint8Array, void, unknown>), contentType?: string): void;
|
|
37
|
+
getBody(responseContentType?: string): SupportedBodyTypes;
|
|
21
38
|
private getSlicedBody;
|
|
22
39
|
/**
|
|
23
40
|
* Sometimes, we need to set the fileSize explicitly because we can't calculate
|
|
@@ -29,23 +46,18 @@ export declare class ByteRangeContext {
|
|
|
29
46
|
getFileSize(): number | null | undefined;
|
|
30
47
|
private isValidByteStart;
|
|
31
48
|
private isValidByteEnd;
|
|
49
|
+
private isValidByteRange;
|
|
32
50
|
/**
|
|
33
51
|
* We may get the values required to determine if this is a valid range request at different times
|
|
34
52
|
* so we need to calculate it when asked.
|
|
35
53
|
*/
|
|
36
54
|
get isValidRangeRequest(): boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Given all the information we have, this function returns the offset that will be used when:
|
|
39
|
-
* 1. calling unixfs.cat
|
|
40
|
-
* 2. slicing the body
|
|
41
|
-
*/
|
|
42
|
-
get offset(): number;
|
|
43
55
|
/**
|
|
44
56
|
* Given all the information we have, this function returns the length that will be used when:
|
|
45
57
|
* 1. calling unixfs.cat
|
|
46
58
|
* 2. slicing the body
|
|
47
59
|
*/
|
|
48
|
-
|
|
60
|
+
getLength(range?: ByteRange): number | undefined;
|
|
49
61
|
/**
|
|
50
62
|
* Converts a range request header into helia/unixfs supported range options
|
|
51
63
|
* Note that the gateway specification says we "MAY" support multiple ranges (https://specs.ipfs.tech/http-gateways/path-gateway/#range-request-header) but we don't
|
|
@@ -56,14 +68,23 @@ export declare class ByteRangeContext {
|
|
|
56
68
|
* Range: bytes=<range-start>-<range-end>
|
|
57
69
|
* Range: bytes=<range-start>-
|
|
58
70
|
* Range: bytes=-<suffix-length> // must pass size so we can calculate the offset. suffix-length is the number of bytes from the end of the file.
|
|
59
|
-
*
|
|
60
|
-
* NOT SUPPORTED:
|
|
61
71
|
* Range: bytes=<range-start>-<range-end>, <range-start>-<range-end>
|
|
62
72
|
* Range: bytes=<range-start>-<range-end>, <range-start>-<range-end>, <range-start>-<range-end>
|
|
63
73
|
*
|
|
64
74
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range#directives
|
|
65
75
|
*/
|
|
66
76
|
private setOffsetDetails;
|
|
77
|
+
/**
|
|
78
|
+
* Helper to convert a SliceableBody to a Uint8Array
|
|
79
|
+
*/
|
|
80
|
+
private convertToUint8Array;
|
|
81
|
+
private getMultipartBody;
|
|
82
|
+
private getSlicedBodyForRange;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the content type for the response.
|
|
85
|
+
* For multipart ranges, this will be multipart/byteranges with a boundary.
|
|
86
|
+
*/
|
|
87
|
+
getContentType(): string | undefined;
|
|
67
88
|
/**
|
|
68
89
|
* This function returns the value of the "content-range" header.
|
|
69
90
|
*
|
|
@@ -76,5 +97,7 @@ export declare class ByteRangeContext {
|
|
|
76
97
|
* - Content-Range: <unit> <byteStart>-<byteEnd>/*
|
|
77
98
|
*/
|
|
78
99
|
get contentRangeHeaderValue(): string;
|
|
100
|
+
private createRangeStream;
|
|
79
101
|
}
|
|
102
|
+
export {};
|
|
80
103
|
//# sourceMappingURL=byte-range-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"byte-range-context.d.ts","sourceRoot":"","sources":["../../../src/utils/byte-range-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"byte-range-context.d.ts","sourceRoot":"","sources":["../../../src/utils/byte-range-context.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,KAAK,EAAE,eAAe,EAAU,MAAM,mBAAmB,CAAA;AAIhE,UAAU,YAAY;IACpB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CACxB;AAED,UAAU,SAAU,SAAQ,YAAY;IACtC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CACzB;AAuDD,qBAAa,gBAAgB;IAqBW,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;IApB/D,SAAgB,cAAc,EAAE,OAAO,CAAA;IAEvC;;OAEG;IACH,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IACvD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0D;IACxF,OAAO,CAAC,UAAU,CAAkB;IACpC,QAAQ,CAAC,mBAAmB,E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