[HtmlUnit] [htmlunit:bugs] #1970 Default request header overwrite request-specific ones
RBRi via HtmlUnit-develop <[email protected]>
| Newsgroups | gmane.comp.java.htmlunit.devel |
|---|---|
| Message-ID | </p/htmlunit/bugs/1970/68a6e8f53cb5fc3008284778aa1fd6d0621da153.bugs@htmlunit.p.sourceforge.net> |
- **status**: open --> closed
- **assigned_to**: RBRi
- **Comment**:
Fixed in SVN; will create a new snapshot build. The ff60 integration still requires some time.
---
** [bugs:#1970] Default request header overwrite request-specific ones**
**Status:** closed
**Group:** 2.31
**Created:** Wed Jun 20, 2018 07:57 AM UTC by Hartmut Arlt
**Last Updated:** Wed Jun 20, 2018 07:57 AM UTC
**Owner:** RBRi
Hi Guys,
We have noticed that the default request header - added via `WebClient#addRequestHeader(String,String)` - are unconditionally added to the request passed in `WebClient#loadWebResponse(WebRequest)`. This causes any headers already set at the request to be overwritten.
As far as I understand, default headers have lower priority than the request-specific ones. Thus, the method `WebClient#addDefaultHeaders(WebRequest)` should add only those default headers that haven't been already set at the given request:
```java
/**
* Adds the headers that are sent with every request to the specified {@link WebRequest} instance.
* @param wrs the <tt>WebRequestSettings</tt> instance to modify
*/
private void addDefaultHeaders(final WebRequest wrs) {
// Add standard HtmlUnit headers.
if (!wrs.isAdditionalHeader(HttpHeader.ACCEPT_LANGUAGE)) {
wrs.setAdditionalHeader(HttpHeader.ACCEPT_LANGUAGE, getBrowserVersion().getBrowserLanguage());
}
if (getBrowserVersion().hasFeature(HTTP_HEADER_UPGRADE_INSECURE_REQUEST)
&& !wrs.isAdditionalHeader(HttpHeader.UPGRADE_INSECURE_REQUESTS)) {
wrs.setAdditionalHeader(HttpHeader.UPGRADE_INSECURE_REQUESTS, "1");
}
// Add user-specified headers last so that they can override HtmlUnit defaults.
requestHeaders_.forEach((n,v) -> {
if(!wrs.isAdditionalHeader(n)) {
wrs.setAdditionalHeader(n, v);
}
});
}
```
Thanks,
Hartmut
---
Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/bugs/
To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop