Skip to content
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

Port number duplicates in Host header when capturing by HttpClient (3.1 and 4.x) #2525

Closed
asfimport opened this issue Sep 7, 2011 · 2 comments

Comments

@asfimport
Copy link
Collaborator

Tetsuya Takatsuru (Bug 51775):
When I'm capturing by HTTP proxy (implementation is set as HttpClient4),
port number duplicates in Host header as following:

GET /somepath HTTP/1.1
Host: somehost:8080:8080

this occurs only when I use non-default port number like as 8080.

To fix this bug, suppress Host header's port number on making HTTP request.
(patch here as attachment)

Created attachment JMeter_hc4impl_bug.patch: patch fixes this bug instantly.

JMeter_hc4impl_bug.patch
# HG changeset patch
# User Tetsuya Takatsuru <takatsuru.tetsuya@nttcom.co.jp>
# Date 1315359482 -32400
# Branch trunk
# Node ID 9ff7f2c2a4cd0882ee77ca3aa2d32307cbbf53bb
# Parent  91e893dec97660f5b48bc7cb58a5a967b0af9021
port duplicates at Host header when capturing by proxy.

diff -r 91e893dec976 -r 9ff7f2c2a4cd src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
--- a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java	木  8月 18 15:40:00 2011 +0900
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java	水  9月 07 10:38:02 2011 +0900
@@ -630,6 +630,7 @@
                     if (! HEADER_CONTENT_LENGTH.equalsIgnoreCase(n)){
                         String v = header.getValue();
                         if (HEADER_HOST.equalsIgnoreCase(n)) {
+                            String host = v.split(":", 2)[0];
                             // TODO is it a bug that HC 4.x does not add the correct port to the generated Host header?
                             int port = url.getPort();
                             if (port != -1) {
@@ -637,7 +638,7 @@
                                     port = -1; // no need to specify the port if it is the default
                                 }
                             }
-                            request.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(v, port));
+                            request.getParams().setParameter(ClientPNames.VIRTUAL_HOST, new HttpHost(host, port));
                         } else {
                             request.addHeader(n, v);
                         }

Severity: major
OS: All

@asfimport
Copy link
Collaborator Author

@milamberspace (migrated from Bugzilla):
Thanks for report and proposal patch.
This bug impacting the HC4 and HC3 implementations when we are in JMeter Proxy mode.
I've fixed this bug for all HC implementation.

URL: http://svn.apache.org/viewvc?rev=1170701&view=rev
Log:
#2525 - Port number duplicates in Host header when capturing by HttpClient (3.1 and 4.x)

Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java
jakarta/jmeter/trunk/xdocs/changes.xml

@asfimport
Copy link
Collaborator Author

@milamberspace (migrated from Bugzilla):
Repatch.

URL: http://svn.apache.org/viewvc?rev=1170866&view=rev
Log:
#2525 - Port number duplicates in Host header when capturing by HttpClient (3.1 and 4.x)
Simplify and improve last fix. Thanks sebb.

Modified:
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant