Import
Basic Usage
Proxy requests to another server:Function Signature
string | URL | Request
required
The destination URL or Request object to proxy to
ProxyRequestInit
Optional configuration object (extends RequestInit with proxy-specific options)
Promise<Response> - A Response object ready to be returned from your handler
Proxy Options
raw
Pass the original request to copy method, body, and headers:Request
Original Request object to copy method, body, and headers from
headers
Customize or override headers:HeadersInit | Record<string, string | undefined>
Headers to send with the proxied request. Set to
undefined to remove a header.customFetch
Use a custom fetch implementation:(request: Request) => Promise<Response>
Custom fetch function for making the proxied request
strictConnectionProcessing
Enable RFC 9110 compliant Connection header processing:boolean
default:"false"
false(default): Ignores Connection header to prevent Hop-by-Hop Header Injection attacks. Recommended for untrusted clients.true: Processes Connection header per RFC 9110 and removes listed headers. Only use in trusted environments.
Complete Example
Simple Proxy
Forward All Request Data
Proxy the entire request including method, body, and headers:Modify Response
Modify the proxied response before returning:Add Authentication
Add authentication to proxied requests:Handle Query Parameters
Automatic Processing
The proxy helper automatically:Removes Hop-by-Hop Headers
The following headers are automatically removed from both request and response per RFC 2616:ConnectionKeep-AliveProxy-AuthenticateProxy-AuthorizationTETrailerTransfer-EncodingUpgrade
Handles Accept-Encoding
TheAccept-Encoding header is automatically removed from the request. The runtime will handle compression natively.
Handles Content-Encoding
If the response hasContent-Encoding, it’s removed along with Content-Length to prevent decompression issues.
Security Considerations
Validation Example
Restrict proxy destinations for security:Error Handling
Handle fetch errors gracefully:Type Definitions
Best Practices
Validate Destinations
Always validate or allowlist destination URLs to prevent open proxy vulnerabilities
Control Headers
Explicitly specify which headers to forward rather than forwarding all headers
Remove Credentials
Set sensitive headers like
Authorization to undefined when they shouldn’t be forwardedHandle Errors
Wrap proxy calls in try-catch blocks and return appropriate error responses
The proxy helper returns a fully-formed Response object that can be returned directly from your handler or modified before returning.