Kind: Function
Source: src/adapter/aws-lambda/handler.ts
Part of: Adapter
Check if the given content type is binary.
This is a default function and may be overwritten by the user via isContentTypeBinary option in handler().
defaultIsContentTypeBinary checks a response Content-Type and returns whether AWS Lambda should treat the response body as binary data. It is the default predicate used by handler(), which can be replaced through the isContentTypeBinary handler option.
Signature
tsfunction defaultIsContentTypeBinary(contentType: string): boolean
Parameters
| Name | Type |
|---|---|
contentType | string |
Returns: boolean
Diagram
mermaidgraph LR Response[Response Content-Type] --> Check[defaultIsContentTypeBinary] Check -->|binary| Encode[Base64 encode body] Check -->|text| Body[Return body as text] Override[isContentTypeBinary option] --> Check
Usage
tsimport { handler } from 'hono/aws-lambda'
import { Hono } from 'hono'
const app = new Hono()
app.get('/report', (c) => {
return c.body(new Uint8Array([1, 2, 3]), {
headers: {
'Content-Type': 'application/pdf',
},
})
})
export const lambdaHandler = handler(app, {
isContentTypeBinary: (contentType) =>
contentType.startsWith('application/pdf') ||
contentType.startsWith('image/'),
})
AI Coding Instructions
- Keep the predicate input limited to the response
Content-Typestring. - Return a boolean that determines whether the Lambda response body is Base64 encoded.
- Pass custom binary-type rules through
handler()usingisContentTypeBinary. - Include custom media types when an endpoint returns non-text response bodies.
Was this page helpful?