Bug 51238

Summary: Allow overriding Host and other restricted headers
Product: JMeter - Now in Github Reporter: Hari Krishna Dara <haridara>
Component: HTTPAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: 2.4   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Hari Krishna Dara 2011-05-21 01:05:30 UTC
Currently the if you add the "Host" header to the "HTTP Header Manager", it gets silently dropped by the underlying java HTTP stack, because this is considered one of the restricted headers. However, the behavior can be changed by simply setting the system property named "sun.net.http.allowRestrictedHeaders" to "true". I have verified that by passing -Dsun.net.http.allowRestrictedHeaders=true argument on the command-line, the "Host" header does indeed work.

Since this header is essential in testing the virtualhost functionality (without having to resort to editing hosts file on each of the load m/c, or depending on the network configuration), I request that JMeter set this property by default during the startup and allow overriding the Host header. Some research is required on what other restricted headers exist and what the consequence might be, but since we are in the business of testing HTTP, I can't imagine any harm of allowing any and all.

The workaround of passing this property on the command-line is not very flexible since it would involve changing any existing scripts that auto-start jmeter. I have looked at an alternative to programmatically change this property during the test run by calling __setProperty() in the context of a user defined variable, but that didn't help. If there is another location where changing this property could get it working, it could be considered an adequate workaround, and should be documented.
Comment 1 Sebb 2011-05-21 09:08:11 UTC
Thanks for the information - useful to know why the header was being ignored.

System properties can be defined in the file "bin/system.properties" which is processed at startup, so should apply to the HTTP implementation.

No code change needed; just edit the file.

I'm not convinced that this should be the default.

Note that the Java HTTP implementation has other failings; in general the Apache HttpClient implementation (3.1 currently, will also support 4.x in the next release) is much more flexible.
Comment 2 Hari Krishna Dara 2011-05-21 16:52:23 UTC
Thanks for the clarification on the bin/system.properties, this is probably a good workaround. Is there a plan to switch to the Apache HttpClient for a future release?
Comment 3 Sebb 2011-05-22 12:06:57 UTC
On further reflection, I think the setting

-Dsun.net.http.allowRestrictedHeaders=true

should be the default for JMeter. JMeter should be able to set such properties.

URL: http://svn.apache.org/viewvc?rev=1125933&view=rev
Log:
Define sun.net.http.allowRestrictedHeaders=true by default. This fixes Bug 51238.

Modified:
   jakarta/jmeter/trunk/bin/system.properties
   jakarta/jmeter/trunk/xdocs/changes.xml
Comment 4 Hari Krishna Dara 2011-05-23 05:57:16 UTC
Thank you.
Comment 5 The ASF infrastructure team 2022-09-24 20:37:46 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/2492