Skip to content

Add Host extractor with X-Forwarded-Host support #21

@aram356

Description

@aram356

Description

Add extractors for obtaining the hostname from HTTP requests:

Host extractor

Extracts the hostname from the standard Host header only. Falls back to "localhost" if not present.

#[action]
pub async fn handler(Host(host): Host) -> Response {
    // host = value from Host header only
}

ForwardedHost extractor

Extracts the effective hostname, checking X-Forwarded-Host first (set by reverse proxies/load balancers), then falling back to the Host header.

#[action]
pub async fn handler(ForwardedHost(host): ForwardedHost) -> Response {
    // host = X-Forwarded-Host if present, otherwise Host header
}

Acceptance Criteria

  • Host extractor extracts from Host header only
  • ForwardedHost extractor prioritizes X-Forwarded-Host over Host
  • Both fall back to "localhost" when no headers present
  • Unit tests for all scenarios
  • Deref and into_inner() methods available on both

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions