-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added optional X-Request-Id to RemoteIpFilter #758
base: main
Are you sure you want to change the base?
Conversation
Will happily review in the next couple of days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be in the valve to be added to a host element.
I also think, maybe with a second PR this value should be natively accessible in the access log valve.
/** | ||
* @see #setRequestIdHeader(String) | ||
*/ | ||
private String requestIdHeader = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the current state of the implementation I made it "backwards compatible" in the sense that no header is set. Yes, we can set it to null
but empty String does not add a risk of NPE so I'm not sure if using null
adds value.
I'm happy to change it to null if others think that it's more appropriate.
I was hoping to reuse Ideally, Valve's invoke() would take an interface like HttpServletRequest rather than the concrete implementation of connector.Request. What does connector.Request add on top of HttpServletRequest? Is it possible to change the Valve interface so that invoke() takes the HttpServletRequest interface? My objective is to be able to either set the Another option might be to make XForwardedRequest extend connector.Request, but that would require a reference to the Connector and coyote.Request which I don't think is available as the original call of the filterChain is from StandardWrapperValve:
So while request is connector.Request, the filter chain receives an instance of RequestFacade... Perhaps I shouldn't try to reuse XForwardedRequest after all? I will still need to expose setRequestId() though 🤔 Any thoughts? cc @rmaucher @markt-asf |
From memory of previous discussions, implementing Request/Response wrapping in Valves is non-trivial. I'd expose a setter for |
This patch adds an optional
requestIdHeader
configuration toRemoteIpFilter
, that when used, sets theXForwardedRequest.requestId
to the value passed with that header.By default,
requestIdHeader
is set to an empty string and is effectively disabled, thus maintaining backwards compatibility. Setting a value in the filter config, e.g. to "X-Request-Id", allows proxy servers or the client application to specify a Request ID, e.g.X-Request-Id: abcd-1234
which is then returned via getReuqestId().I wanted to do the same for
RemoteIpValve
but it looks like there we do not use theXForwardedRequest
and other changes will be required.Feedback welcome.