-
Notifications
You must be signed in to change notification settings - Fork 910
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
Add Clients.newContextCaptor()
#2344
Conversation
Motivation: It'd be nice if a user can capture the `ClientRequestContext` of the request being sent without using a decorator. Modifications: - Add `Clients.captureNextContext()` and `capturedContext()` - Add `ClientRequestContextCustomizers` which replaces the functional composition of `Consumer<ClientRequestContext>`s. - Copy the customizer list when a `DefaultClientRequestContext` is constructed, so that thread-local customizers are evaluated even if an actual request starts from a different thread. - Add `? super` to some type parameters for user convenience. Result: - Closes line#1739 - Fixed a bug where `Clients.withHttpHeaders()` and `withContextCustomizer()` don't work for gRPC clients.
Codecov Report
@@ Coverage Diff @@
## master #2344 +/- ##
=========================================
Coverage ? 73.62%
Complexity ? 10483
=========================================
Files ? 928
Lines ? 40101
Branches ? 4944
=========================================
Hits ? 29524
Misses ? 8068
Partials ? 2509
Continue to review full report at Codecov.
|
uri().getRawPath(), | ||
uri().getRawQuery(), | ||
req.path(), | ||
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.
This fixes a bug in the gRPC client where a wrong path (usually /
) is set to the context. /cc @anuraaga
core/src/main/java/com/linecorp/armeria/client/DefaultClientRequestContext.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/DefaultClientRequestContext.java
Outdated
Show resolved
Hide resolved
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.
👍
@@ -91,6 +86,36 @@ void deriveContext() { | |||
assertThat(derivedCtx.attr(bar).get()).isEqualTo(null); | |||
} | |||
|
|||
@Test | |||
void derivedContextMustNotCallCustomizers() { |
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.
Thanks!
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.
Awesome work! Updated two nit indentations in Javadoc 8eca4db because of your day off. 😉
return execute(null, req); | ||
} | ||
|
||
private HttpResponse execute(@Nullable EventLoop eventLoop, HttpRequest req) { |
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.
Nice! 👍
core/src/main/java/com/linecorp/armeria/client/ClientRequestContextCustomizers.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientRequestContextCustomizers.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/DefaultClientRequestContext.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientRequestContextCustomizers.java
Outdated
Show resolved
Hide resolved
thrift/src/test/java/com/linecorp/armeria/client/thrift/ThriftOverHttpClientTest.java
Outdated
Show resolved
Hide resolved
Clients.captureNextContext()
and capturedContext()
Clients.newContextCaptor()
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.
It looks better than before. 😉
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.
Still LGTM
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.
LGTM code-wise but still have concern about the thread local handling for captor.
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.
Thanks!
core/src/main/java/com/linecorp/armeria/client/ClientThreadLocalState.java
Outdated
Show resolved
Hide resolved
Added a few utility methods to |
Thanks for reviewing! |
Motivation: It'd be nice if a user can capture the `ClientRequestContext` of the request being sent without using a decorator. Modifications: - Add `Clients.newContextCaptor()` - Add `ClientThreadLocalState` which replaces the functional composition of `Consumer<ClientRequestContext>`s. - Copy the customizer list when a `DefaultClientRequestContext` is constructed, so that thread-local customizers are evaluated even if an actual request starts from a different thread. - Add `? super` to some type parameters for user convenience. - Miscellaneous: - Fix a bug in the gRPC client where a wrong path (usually /) is set to the context. - Make `ClientRequestContext.ownAttr()` nullable. Result: - Closes line#1739 - Fixed a bug where thread-local context customizers were called for derived contexts unintentionally. - Fixed a bug where `Clients.withHttpHeaders()` and `withContextCustomizer()` don't work for gRPC clients. - Fixed a bug in the gRPC client where a wrong path (usually /) is set to the context.
Motivation:
It'd be nice if a user can capture the
ClientRequestContext
of therequest being sent without using a decorator.
Modifications:
Clients.newContextCaptor()
ClientThreadLocalState
which replaces the functionalcomposition of
Consumer<ClientRequestContext>
s.DefaultClientRequestContext
isconstructed, so that thread-local customizers are evaluated even if
an actual request starts from a different thread.
? super
to some type parameters for user convenience.ClientRequestContext.ownAttr()
nullable.Result:
ClientRequestContext
without using a decorator. #1739Clients.withHttpHeaders()
andwithContextCustomizer()
don't work for gRPC clients.