[ 
https://issues.apache.org/jira/browse/HTTPCLIENT-2267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17706703#comment-17706703
 ] 

Oleg Kalnichevski commented on HTTPCLIENT-2267:
-----------------------------------------------

[~patrickjamesbarry] The behavior of HttpClient 5.1 is wrong. It triggers the 
protocol handling logic in the protocol interceptor chain _before_ the protocol 
version has been fully negotiated, making it impossible for the request 
interceptors to modify the populate message based on the protocol version. This 
problem has been corrected in HttpClient 5.2.

Just move your validation logic from the request interceptor into an exec 
interceptor and place that interceptor before the `PROTOCOL` element in the 
execution chain.

https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientInterceptors.java

Oleg



> Connect called before Interceptors are invoked
> ----------------------------------------------
>
>                 Key: HTTPCLIENT-2267
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-2267
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient (async)
>    Affects Versions: 5.2.1
>            Reporter: Patrick Barry
>            Priority: Major
>
> We tried to migrated to 5.2.1 from 5.1.4.  Right away, our unit tests showed 
> us that our HttpRequestInterceptor that was registered 
> "addRequestInterceptorFirst" is not called before a connection is attempted 
> to be established.  Expected behaviour is that our interceptor validation 
> would catch malformed urls, etc  and kick out a known error to us.  Now, 
> NoRouteToHostException is being thrown before our interceptor logic is hit.  
> The 'bad url' we were using in our test is:
> [https://google.com:555|https://google.com:555/]
>  
> To recreate, standup new HttpAsyncClient, register an interceptor in first 
> position and force it to use HTTP 1.1, and then generate a GET request to 
> [https://google.com:555|https://google.com:555/]
>  
> {code:java}
> java.net.NoRouteToHostException: No route to host
>     at java.base/sun.nio.ch.Net.connect0(Native Method)
>     at java.base/sun.nio.ch.Net.connect(Net.java:579)
>     at java.base/sun.nio.ch.Net.connect(Net.java:586)
>     at 
> java.base/sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:853)
>     at 
> org.apache.hc.core5.reactor.SingleCoreIOReactor.lambda$processConnectionRequest$0(SingleCoreIOReactor.java:336)
>     at 
> java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
>     at 
> org.apache.hc.core5.reactor.SingleCoreIOReactor.processConnectionRequest(SingleCoreIOReactor.java:335)
>     at 
> org.apache.hc.core5.reactor.SingleCoreIOReactor.processPendingConnectionRequests(SingleCoreIOReactor.java:307)
>     at 
> org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:138)
>     at 
> org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:86)
>     at 
> org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
>     at java.base/java.lang.Thread.run(Thread.java:833) {code}
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to