tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

fetch-event-respond-with-custom-response-worker.js (1043B)


      1 'use strict';
      2 
      3 addEventListener('fetch', event => {
      4  const url = new URL(event.request.url);
      5  const type = url.searchParams.get('type');
      6 
      7  if (!type) return;
      8 
      9  if (type === 'string') {
     10    event.respondWith(new Response('PASS'));
     11  }
     12  else if (type === 'blob') {
     13    event.respondWith(
     14      new Response(new Blob(['PASS']))
     15    );
     16  }
     17  else if (type === 'buffer-view') {
     18    const encoder = new TextEncoder();
     19    event.respondWith(
     20      new Response(encoder.encode('PASS'))
     21    );
     22  }
     23  else if (type === 'buffer') {
     24    const encoder = new TextEncoder();
     25    event.respondWith(
     26      new Response(encoder.encode('PASS').buffer)
     27    );
     28  }
     29  else if (type === 'form-data') {
     30    const body = new FormData();
     31    body.set('result', 'PASS');
     32    event.respondWith(
     33      new Response(body)
     34    );
     35  }
     36  else if (type === 'search-params') {
     37    const body = new URLSearchParams();
     38    body.set('result', 'PASS');
     39    event.respondWith(
     40      new Response(body, {
     41        headers: { 'Content-Type': 'text/plain' }
     42      })
     43    );
     44  }
     45 });