Skip to content

feat: add remote address extractor - #673

Draft
Wervice wants to merge 2 commits into
cot-rs:masterfrom
Wervice:ip-extractor
Draft

Wervice wants to merge 2 commits into
cot-rs:masterfrom
Wervice:ip-extractor

Conversation

@Wervice

@Wervice Wervice commented Sep 15, 2026

Copy link
Copy Markdown

I added an extractor RemoteAddr in the extractors.rs. This extractor works by getting an extension from the HTTP headers which contains the remote address.
For this extension to be set, axum has to be started with handler.into_make_service_with_connect_info.
The extractor then provides the IP address. Furthermore, when a proxied connection was declared using one of the following headers, the proxied IP will be used:

  • CF-Connecting-IP
  • CloudFront-Viewer-Address
  • Fly-Client-IP
  • Forwarded
  • X-Forwarded-For
  • True-Client-IP
  • X-Envoy-External-Address
  • X-Real-Ip

In order to implement proxied HTTP header detection the client_ip crate was used.
In order to comply with the orphan rules, cot-core was given access to tokio via tokio.workspace = true.

Related issue or discussion

Description

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor / cleanup
  • Performance improvement
  • Other (describe above)

Checklist

  • I've read the contributing guide
  • [ X Tests pass locally (just test-all)
  • Code passes clippy (just clippy)
  • Code is properly formatted (cargo fmt)
  • New tests added (regression test for bugs, coverage for new features)
  • Documentation (both code and site) updated (if applicable)

I added an extractor `RemoteAddr` in the `extractors.rs`.
This extractor works by getting an extension from the HTTP headers which
contains the remote address.
For this extension to be set, axum has to be started with
`handler.into_make_service_with_connect_info`.
The extractor then provides the IP address. Furthermore, when a proxied
connection was declared using one of the following headers, the proxied
IP will be used:
- CF-Connecting-IP
- CloudFront-Viewer-Address
- Fly-Client-IP
- Forwarded
- X-Forwarded-For
- True-Client-IP
- X-Envoy-External-Address
- X-Real-Ip

In order to implement proxied HTTP header detection the `client_ip`
crate was used.
In order to comply with the orphan rules, `cot-core` was given access to
`tokio` via `tokio.workspace = true`.
@github-actions github-actions Bot added C-lib Crate: cot (main library crate) C-core labels Sep 15, 2026
@Wervice Wervice changed the title Added IP address extractor feat: add remote address extractor Sep 15, 2026
@Wervice
Wervice marked this pull request as draft September 16, 2026 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-core C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant