@helia/verified-fetch
Version:
A fetch-like API for obtaining verified & trustless IPFS content on the web
25 lines • 998 B
JavaScript
import { ByteRangeContext } from '../utils/byte-range-context.js';
import { badRangeResponse } from '../utils/responses.js';
import { BasePlugin } from './plugin-base.js';
/**
* This plugin simply adds the ByteRangeContext to the PluginContext.
*/
export class ByteRangeContextPlugin extends BasePlugin {
id = 'byte-range-context-plugin';
/**
* Return false if the ByteRangeContext has already been set, otherwise return true.
*/
canHandle(context) {
return context.byteRangeContext == null;
}
async handle(context) {
context.byteRangeContext = new ByteRangeContext(this.pluginOptions.logger, context.options?.headers);
context.modified++;
if (context.byteRangeContext.isRangeRequest && !context.byteRangeContext.isValidRangeRequest) {
// invalid range request.. fail
return badRangeResponse(context.resource);
}
return null;
}
}
//# sourceMappingURL=plugin-handle-byte-range-context.js.map