ktorio / ktorio/ktor

XForwardedHeaderSupport is installed late in the pipeline

Open
#680 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
14.5k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
49

Description

Currently, it's installed in the `ApplicationCallPipeline.Features` phase. This is fine for route handlers that want to access `call.request.origin.remoteHost`, etc, but is problematic for other features that might want to use the info that `XFHS` provides.

As an example, I'm writing a feature that captures request metadata and puts it in a ThreadLocal (via [`asContextElement`](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/java.lang.-thread-local/as-context-element.html)) so that when writing to GCP's logging service, the [HttpRequest](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest) element can be populated automatically for any logging calls that are done in the coroutine context of a request. Naturally, it would be nice to populate the actual client ip here.

The `Monitoring` phase sounds like what I want from the docs:

> Phase for tracing calls, useful for logging, metrics, error handling and so on

However, if I intercept there, I won't get to use the data from `XFHS`. My current workaround is to intercept in `Features` as the last feature I add there so that the changes applied by `XFHS` are visible, but that's not ideal: now logging done by features in `Monitoring` won't have their log entries enriched with request metadata at all.

Contributor guide

Open the contributing guide

Research direction

Start at XForwardedHeaderSupport and its installation in the ApplicationCallPipeline.Features phase. Read the ApplicationCallPipeline phase documentation, especially Monitoring and Features, and trace which features consume the forwarded-header data. Done means features running in Monitoring can access that data while request origin access in route handlers continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.