Spaces:
Paused
Paused
Download node_modules/msw/src/browser/utils/pruneGetRequestBody.ts from sam522/GenAI_Course: direct link, hf CLI and curl.
- Browser
- Download file 703 Bytes
-
https://huggingface.co/spaces/sam522/GenAI_Course/resolve/bbf0eafbb40cb551e2f40f8ad8a90a585be08221/node_modules/msw/src/browser/utils/pruneGetRequestBody.ts
- Command line
-
hf download hf://spaces/sam522/GenAI_Course@bbf0eafbb40cb551e2f40f8ad8a90a585be08221/node_modules/msw/src/browser/utils/pruneGetRequestBody.ts
-
curl -L -o pruneGetRequestBody.ts https://huggingface.co/spaces/sam522/GenAI_Course/resolve/bbf0eafbb40cb551e2f40f8ad8a90a585be08221/node_modules/msw/src/browser/utils/pruneGetRequestBody.ts
703 Bytes
| import type { ServiceWorkerIncomingRequest } from '../setupWorker/glossary' | |
| type Input = Pick<ServiceWorkerIncomingRequest, 'method' | 'body'> | |
| /** | |
| * Ensures that an empty GET request body is always represented as `undefined`. | |
| */ | |
| export function pruneGetRequestBody( | |
| request: Input, | |
| ): ServiceWorkerIncomingRequest['body'] { | |
| // Force HEAD/GET request body to always be empty. | |
| // The worker reads any request's body as ArrayBuffer, | |
| // and you cannot re-construct a GET/HEAD Request | |
| // with an ArrayBuffer, even if empty. Also note that | |
| // "request.body" is always undefined in the worker. | |
| if (['HEAD', 'GET'].includes(request.method)) { | |
| return undefined | |
| } | |
| return request.body | |
| } | |