@helia/verified-fetch 3.0.2 → 3.1.1
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 +61 -49
- 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 +7 -4
- 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/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 +1 -1
- package/src/plugins/plugin-handle-byte-range-context.ts +6 -0
- package/src/plugins/plugin-handle-car.ts +7 -4
- 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/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
package/src/utils/responses.ts
CHANGED
|
@@ -167,14 +167,27 @@ export function okRangeResponse (url: string, body: SupportedBodyTypes, { byteRa
|
|
|
167
167
|
|
|
168
168
|
let response: Response
|
|
169
169
|
try {
|
|
170
|
+
// Create headers object with any initial headers from init
|
|
171
|
+
const headers = new Headers(init?.headers)
|
|
172
|
+
|
|
173
|
+
// For multipart responses, we should use the content-type header instead of content-range
|
|
174
|
+
const multipartContentType = byteRangeContext.getContentType()
|
|
175
|
+
|
|
176
|
+
if (multipartContentType != null) {
|
|
177
|
+
headers.set('content-type', multipartContentType)
|
|
178
|
+
} else {
|
|
179
|
+
if (byteRangeContext.isMultiRangeRequest) {
|
|
180
|
+
headers.set('content-type', 'multipart/byteranges')
|
|
181
|
+
} else {
|
|
182
|
+
headers.set('content-range', byteRangeContext.contentRangeHeaderValue)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
170
186
|
response = new Response(body, {
|
|
171
187
|
...(init ?? {}),
|
|
172
188
|
status: 206,
|
|
173
189
|
statusText: 'Partial Content',
|
|
174
|
-
headers
|
|
175
|
-
...(init?.headers ?? {}),
|
|
176
|
-
'content-range': byteRangeContext.contentRangeHeaderValue
|
|
177
|
-
}
|
|
190
|
+
headers
|
|
178
191
|
})
|
|
179
192
|
} catch (e: any) {
|
|
180
193
|
log?.error('failed to create range response', e)
|
package/src/verified-fetch.ts
CHANGED
|
@@ -165,7 +165,7 @@ export class VerifiedFetch {
|
|
|
165
165
|
// if there are multiple ranges, we should omit the content-length header. see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Transfer-Encoding
|
|
166
166
|
if (response.headers.get('Transfer-Encoding') !== 'chunked') {
|
|
167
167
|
if (byteRangeContext != null) {
|
|
168
|
-
const contentLength = byteRangeContext.
|
|
168
|
+
const contentLength = byteRangeContext.getLength()
|
|
169
169
|
if (contentLength != null) {
|
|
170
170
|
this.log.trace('Setting Content-Length from byteRangeContext: %d', contentLength)
|
|
171
171
|
response.headers.set('Content-Length', contentLength.toString())
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"set-content-type.d.ts","sourceRoot":"","sources":["../../../src/utils/set-content-type.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,QAAQ,CAAA;IAClB,kBAAkB,CAAC,EA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