new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Hono · all subjects

helpers/proxy

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

proxy() function overview

proxy() is a fetch() API wrapper for proxy use cases. The parameters and return value are the same as fetch() except for proxy-specific options. The Accept-Encoding header is replaced with an encoding the current runtime can handle. Unnecessary response headers are removed, and a Response object is returned that can be sent from the handler.

proxy() simple example

app.get('/proxy/:path', (c) => { return proxy(`http://${originServer}/${c.req.param('path')}`) })

proxy() with headers and c.req parameter

app.all('/proxy/:path', (c) => { return proxy(`http://${originServer}/${c.req.param('path')}`, { ...c.req, // optional, specify only when forwarding all the request data (including credentials) is necessary. headers: { ...c.req.header(), 'X-Forwarded-For': '127.0.0.1', 'X-Forwarded-Host': c.req.header('host'), Authorization: undefined, // do not propagate request headers contained in c.req.header('Authorization') }, }) })

proxy() with customFetch option

app.get('/proxy', (c) => { return proxy('https://example.com/', { customFetch, }) }) You can override the default global fetch function with the customFetch option.

Connection header processing in proxy()

By default, proxy() ignores the Connection header to prevent Hop-by-Hop Header Injection attacks. You can enable strict RFC 9110 compliance with the strictConnectionProcessing option set to true. Use strictConnectionProcessing only in trusted environments.

proxy() with strictConnectionProcessing

// Default behavior (recommended for untrusted clients) app.get('/proxy/:path', (c) => { return proxy(`http://${originServer}/${c.req.param('path')}`, c.req) }) // Strict RFC 9110 compliance (use only in trusted environments) app.get('/internal-proxy/:path', (c) => { return proxy(`http://${internalServer}/${c.req.param('path')}`, { ...c.req, strictConnectionProcessing: true, }) })

ProxyRequestInit interface

interface ProxyRequestInit extends Omit<RequestInit, 'headers'> { raw?: Request customFetch?: (request: Request) => Promise<Response> strictConnectionProcessing?: boolean headers?: HeadersInit | [string, string][] | Record<RequestHeader, string | undefined> | Record<string, string | undefined> }

ProxyFetch interface

interface ProxyFetch { (input: string | URL | Request, init?: ProxyRequestInit): Promise<Response> }

proxy() import

import { Hono } from 'hono' import { proxy } from 'hono/proxy'

Give your agent this brain