File
Blob: src/workerd/api/tests/data-url-fetch-test.js
| 1 | // Copyright (c) 2024 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | import { strictEqual } from 'node:assert'; |
| 5 | |
| 6 | export const dataUrl = { |
| 7 | async test() { |
| 8 | const resp = await fetch('data:text/plain,Hello%2C%20World!'); |
| 9 | strictEqual(resp.status, 200); |
| 10 | strictEqual(resp.statusText, 'OK'); |
| 11 | strictEqual(await resp.text(), 'Hello, World!'); |
| 12 | strictEqual(resp.headers.get('content-type'), 'text/plain'); |
| 13 | }, |
| 14 | }; |
| 15 | |
| 16 | export const base64DataUrl = { |
| 17 | async test() { |
| 18 | const resp = await fetch( |
| 19 | ' DATA:text/plain;a="b";base64,\t\nSGVsbG8sIFdvcmxkIQ%3D%3D' |
| 20 | ); |
| 21 | strictEqual(resp.status, 200); |
| 22 | strictEqual(resp.statusText, 'OK'); |
| 23 | strictEqual(await resp.text(), 'Hello, World!'); |
| 24 | strictEqual(resp.headers.get('content-type'), 'text/plain;a=b'); |
| 25 | }, |
| 26 | }; |