@@ -224,12 +224,6 @@ export class Driver implements Debuggable, UpdateSource {
224224 return ;
225225 }
226226
227- // Calls range request handler
228- if ( req . headers . has ( 'range' ) ) {
229- event . respondWith ( this . handleRangeRequest ( req ) ) ;
230- return ;
231- }
232-
233227 // The only thing that is served unconditionally is the debug page.
234228 if ( requestUrlObj . path === this . ngswStatePath ) {
235229 // Allow the debugger to handle the request, but don't affect SW state in any other way.
@@ -283,63 +277,6 @@ export class Driver implements Debuggable, UpdateSource {
283277 event . respondWith ( this . handleFetch ( event ) ) ;
284278 }
285279
286- // function to handle Range requests
287- private async handleRangeRequest ( req : Request ) : Promise < Response > {
288- try {
289- const response = await fetch ( req ) ;
290- const contentType = response . headers . get ( 'Content-Type' ) ;
291-
292- // Only apply logic to content that is a video
293- if ( ! contentType || ! contentType . startsWith ( 'video/' ) ) {
294- return response ;
295- }
296-
297- const rangeHeader = req . headers . get ( 'range' ) ;
298- if ( ! rangeHeader ) {
299- return new Response ( null , {
300- status : 416 ,
301- statusText : 'Range Not Satisfiable' ,
302- } ) ;
303- }
304-
305- const rangeMatch = / b y t e s = ( \d + ) - ( \d + ) ? / . exec ( rangeHeader ) ;
306- if ( ! rangeMatch ) {
307- return new Response ( null , {
308- status : 416 ,
309- statusText : 'Range Not Satisfiable' ,
310- } ) ;
311- }
312-
313- const start = Number ( rangeMatch [ 1 ] ) ;
314- const end = rangeMatch [ 2 ] ? Number ( rangeMatch [ 2 ] ) : undefined ;
315-
316- const buffer = await response . arrayBuffer ( ) ;
317- const contentLength = buffer . byteLength ;
318-
319- const chunk = buffer . slice ( start , end ? end + 1 : contentLength ) ;
320- const chunkLength = chunk . byteLength ;
321-
322- const headers = new Headers ( response . headers ) ;
323- headers . set (
324- 'Content-Range' ,
325- `bytes ${ start } -${ end ? end : contentLength - 1 } /${ contentLength } ` ,
326- ) ;
327- headers . set ( 'Content-Length' , chunkLength . toString ( ) ) ;
328- headers . set ( 'Accept-Ranges' , 'bytes' ) ;
329-
330- return new Response ( chunk , {
331- status : 206 ,
332- statusText : 'Partial Content' ,
333- headers : headers ,
334- } ) ;
335- } catch ( error ) {
336- return new Response ( null , {
337- status : 500 ,
338- statusText : 'Internal Server Error' ,
339- } ) ;
340- }
341- }
342-
343280 /**
344281 * The handler for message events.
345282 */
0 commit comments