Search code examples
jodd

User-Agent header cannot be removed in jodd-http


I want to send a request without User-Agent for testing purposes. I tried to use headerRemove but it doesn't work. Is there a way to achieve this?

val request = HttpRequest.get("https://example.com")
                         .header("x-dummy-header", "remove me")

headerRemove("x-dummy-header")
headerRemove("User-Agent")
GET / HTTP/1.1
Connection: Close
Host: example.com
User-Agent: Jodd HTTP

Solution

  • Fixed in v6.2.0 (just released:). Jodd Http used to have a default User-Agent, which was set if no such header was present.

    Now you can do one of the two things:

    1. Remove default headers in HttpBase.Defaults.headers - its a map of default headers loaded in every instance of HttpRequest
    2. Simply remove it from the HttpRequest using headerRemove() method or remove all default headers (there is just that one) with the headersClean() method.