Skip to content
Myr

fix(types): allow returning a Blob as a response body (#5446)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent 5f31392 · Browse files · 3 files+27 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+27 added−2 removed

  • tests:+25 added−0 removed
  • other:+2 added−2 removed

3 files+27 added−2 removed

modified:src/middleware/serve-static/index.test.ts+15 added
1import { serveStatic as baseServeStatic } from '.'2import { Hono } from '../../hono'34describe('Serve Static Middleware with a Blob body', () => {5 it('Should serve content returned as a Blob', async () => {6 const app = new Hono()7 app.use(8 '/static/*',9 baseServeStatic({10 getContent: async (path) => new Blob([`Hello in ${path}`]),11 })12 )13 const res = await app.request('http://localhost/static/hello.txt')14 expect(res.status).toBe(200)15 expect(await res.text()).toBe('Hello in static/hello.txt')16 })17})1819describe('Serve Static Middleware', () => {20 const app = new Hono()21 const getContent = vi.fn(async (path) => {22 if (path.endsWith('not-found.txt')) {
314 unmodified lines
modified:src/context.test.ts+10 added
127 unmodified lines
128 expect(res.headers.get('Location')).toBe(urlString)129 })130 })131132 it('c.body() - Blob', async () => {133 const res = c.body(new Blob(['Hi']))134 expect(await res.text()).toBe('Hi')135 })136137 it('c.body() - File', async () => {138 const res = c.body(new File(['Hi'], 'greeting.txt'))139 expect(await res.text()).toBe('Hi')140 })141142 it('c.header()', async () => {143 c.header('X-Foo', 'Bar')144 const res = c.body('Hi')145 const foo = res.headers.get('X-Foo')
484 unmodified lines
modified:src/context.ts+2 added-2 removed
19 unmodified lines
20 | Record<ResponseHeader, string | string[]>21 | Record<string, string | string[]>2223/**24 * Data type can be a string, ArrayBuffer, Uint8Array (buffer), or ReadableStream.24 * Data type can be a string, ArrayBuffer, Blob, Uint8Array (buffer), or ReadableStream.25 */26export type Data = string | ArrayBuffer | ReadableStream | Uint8Array<ArrayBuffer>26export type Data = string | ArrayBuffer | Blob | ReadableStream | Uint8Array<ArrayBuffer>2728/**29 * Interface for the execution context in a web worker or similar environment.30 */
767 unmodified lines