Skip to content

defaultIsContentTypeBinary

reference
1 min readUpdated

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

ts
function defaultIsContentTypeBinary(contentType: string): boolean

Parameters

NameType
contentTypestring

Returns: boolean

Diagram

mermaid
graph 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

ts
import { 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-Type string.
  • Return a boolean that determines whether the Lambda response body is Base64 encoded.
  • Pass custom binary-type rules through handler() using isContentTypeBinary.
  • Include custom media types when an endpoint returns non-text response bodies.

Was this page helpful?

Download as PDF
defaultIsContentTypeBinary — Hono (narrator proof)