[
https://issues.apache.org/jira/browse/HTTPCLIENT-1296?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13549479#comment-13549479
]
Oleg Kalnichevski commented on HTTPCLIENT-1296:
-----------------------------------------------
Karl,
I think the fix should be much simpler. I also believe that the virtual host
rewriting should take place outside of the execution, as it may produce an
incorrect result in case of a cross-site redirect.
Please have a look.
Oleg
---
a/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
+++
b/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
@@ -417,7 +417,8 @@ public class DefaultRequestDirector implements
RequestDirector {
// HTTPCLIENT-1092 - add the port if necessary
if (virtualHost != null && virtualHost.getPort() == -1) {
- int port = target.getPort();
+ HttpHost host = target != null ? target :
origRoute.getTargetHost();
+ int port = host.getPort();
if (port != -1){
virtualHost = new HttpHost(virtualHost.getHostName(), port,
virtualHost.getSchemeName());
> Null pointer exception when using default host and virtual host with port -1
> ----------------------------------------------------------------------------
>
> Key: HTTPCLIENT-1296
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1296
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Affects Versions: 4.2.2
> Reporter: Karl Wright
> Assignee: Karl Wright
> Priority: Critical
> Attachments: HTTPCLIENT-1296.patch
>
>
> The following code in DefaultRequestDirector is incorrect:
> {code}
> // HTTPCLIENT-1092 - add the port if necessary
> if (virtualHost != null && virtualHost.getPort() == -1) {
> int port = target.getPort();
> if (port != -1){
> virtualHost = new HttpHost(virtualHost.getHostName(), port,
> virtualHost.getSchemeName());
> }
> }
> {code}
> The reason it is incorrect is that if the target has not been specified in
> the URL, then an NPE will result. The target is resolved later in the same
> method in that case.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]