Ori Marko
Ori Marko

Reputation: 58822

JMeter - Why sending default User-Agent header

When sending HTTP Request in JMeter, User-Agent header is added,e.g.:

User-Agent: Apache-HttpClient/4.5.10 (Java/1.8.0_191) Content-Type: text/plain Host: api.example.com

I didn't find any reason in documentation,

But there's a reference to its existence in JMeter docs

In this example, we created a Test Plan that tells JMeter to override the default "User-Agent" request header and use a particular Internet Explorer agent string instead.

When changing to Java in Advanced -> Implementation it doesn't send extra headers, so it's related to HTTPClient4

HttpClient sends a default User-Agent header with every request

But what is the reason behind it?

Also when I try to remove it, by adding User-Agent with empty value in Header Manager

Still it sends User-Agent with empty value, is there a way to avoid sending User-Agent header?

Upvotes: 1

Views: 1345

Answers (1)

Dmitri T
Dmitri T

Reputation: 168122

Which documentation? JMeter documentation shouldn't include comprehensive documentation on underlying Java SDK (for Java implementation) or Apache HttpComponents for HttpClient4 implementation.

For the latter one the "explanation" lives inside the HttpClientBuilder class

if (userAgentCopy == null) {
    if (systemProperties) {
        userAgentCopy = System.getProperty("http.agent");
    }
    if (userAgentCopy == null && !defaultUserAgentDisabled) { 
        userAgentCopy = VersionInfo.getUserAgent("Apache-HttpClient",
                "org.apache.http.client", getClass());
    }
}

If there is no User-Agent header supplied the underlying Apache HttpComponents library implicitly adds the default header because clients SHOULD send the User-Agent string according to RFC 2616.

Well-behaved JMeter test should represent real browser as close as possible so given you see this default User-Agent string it indicates that your JMeter setup is not correct so your test results will not be reliable. Check out

Upvotes: 3

Related Questions