Skip to main content
The ConnInfo helper provides type definitions for accessing HTTP connection information, including remote address, port, and transport protocol details. This is useful for logging, security checks, and network debugging.

Import

Type Definitions

The ConnInfo helper exports TypeScript types for working with connection information:

ConnInfo

The main connection information interface:

NetAddrInfo

Network address information for a connection:

AddressType

The type of network address:

GetConnInfo

Helper type for functions that extract connection info from context:

Usage with Adapters

Connection information extraction is adapter-specific. Many runtime adapters provide a getConnInfo function:

Cloudflare Workers

Deno

Bun

Node.js

Common Use Cases

IP Address Logging

Log client IP addresses for requests:

IP-based Rate Limiting

Implement simple IP-based rate limiting:

Geolocation-based Content

Serve different content based on IP address:

Security Checks

Implement IP allowlisting or blocklisting:

Debug Information

Return connection details for debugging:

IPv4 vs IPv6

Check the address type to handle IPv4 and IPv6 differently:

Adapter Availability

Connection info support varies by runtime adapter:

Cloudflare Workers

Full support via hono/cloudflare-workers

Deno

Full support via hono/deno

Bun

Full support via hono/bun

Node.js

Available via @hono/node-server/conninfo
Check your specific adapter’s documentation for getConnInfo availability and implementation details.

Behind Proxies

When your application is behind a proxy or load balancer, the remote address will be the proxy’s IP. Use headers like X-Forwarded-For for the actual client IP:
Security: Only trust X-Forwarded-For and similar headers when you control the proxy. These headers can be spoofed by clients if not properly configured.

Best Practices

Check Adapter Support

Verify your runtime adapter supports getConnInfo before using

Handle Undefined

Always handle cases where address or port may be undefined

Proxy Awareness

Use appropriate headers when behind proxies or load balancers

Privacy Compliance

Be mindful of privacy laws when logging or storing IP addresses