Patrick Barry created HTTPCLIENT-2232:
-----------------------------------------
Summary: Registering RequestInterceptorLast is misleading
Key: HTTPCLIENT-2232
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2232
Project: HttpComponents HttpClient
Issue Type: Bug
Components: HttpClient (async)
Affects Versions: 5.1.3
Reporter: Patrick Barry
{code:java}
CloseableHttpAsyncClient client = HttpAsyncClients.custom()
.addRequestInterceptorLast(new MyRequestInterceptor())
.build();
client.start();{code}
We were registering our request interceptor and were trying to log out some of
the important headers we wish to see on our outgoing requests, like
transfer-encoding. We found out the hard way this header is set later in
processing, in the H2RequestContent class that is registered in the
HttpAsyncClientEventHandlerFactory and later in IOReactor. This is super
frustrating because registering something 'last' should be the last thing that
is hit before reaching out to target. Because we it is not, we do not see the
header we wish to see. We limit the headers we expose, so turning on Wire
logging or something like that is not an option for us. The way the
HttpAsyncClientBuilder is written, I do not have the option of registering my
own interceptor in HttpAsyncClientEventHandlerFactory or even providing my own
IOEventHandlerFactory. What do you guys suggest here? The only option I see
is to manually create our async client, and due to the heavy configuration of
this class, I am hoping for an alternative. FYI- I do not need to change the
outgoing request in any way, this is merely a logging issue for us.
{code:java}
final IOEventHandlerFactory ioEventHandlerFactory = new
HttpAsyncClientEventHandlerFactory(
new DefaultHttpProcessor(new H2RequestContent(), new
H2RequestTargetHost(), new H2RequestConnControl()),
new HandlerFactory<AsyncPushConsumer>() {
@Override
public AsyncPushConsumer create(final HttpRequest request, final
HttpContext context) throws HttpException {
return pushConsumerRegistry.get(request);
}
},
versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,
h2Config != null ? h2Config : H2Config.DEFAULT,
h1Config != null ? h1Config : Http1Config.DEFAULT,
charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
reuseStrategyCopy);
final DefaultConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(
ioEventHandlerFactory,
ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT,
threadFactory != null ? threadFactory : new
DefaultThreadFactory("httpclient-dispatch", true),
LoggingIOSessionDecorator.INSTANCE,
ioReactorExceptionCallback != null ? ioReactorExceptionCallback :
LoggingExceptionCallback.INSTANCE,
null,
new Callback<IOSession>() {
@Override
public void execute(final IOSession ioSession) {
ioSession.enqueue(new ShutdownCommand(CloseMode.GRACEFUL),
Command.Priority.IMMEDIATE);
}
});{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]