- Platform information:
- Hardware: RaspberryPi 4, 8GB
- OS: Raspbian GNU/Linux 10 (buster)
- Java Runtime Environment: Zulu11.50+19-CA (build 11.0.12+7-LTS)
- openHAB version: 3.4.1 - Release Build
Problem: as a user, I would expect sendHttpGetRequest to let the header information I am giving it take precedence over sendHttpGetRequest’s default values.
Description: Using javascript;version=ECMAScript-2021, I am trying to use send a sendHttpGetRequest with certain headers defined in a hashmap. All of the values in the hashmap is used by sendHttpGetRequest except for User-Agent. In the case of User-Agent, two values for User-Agent is sent to the server; the value I gave it in the hashmap and User-Agent: Jetty/9.4.46.v20220331.
Some servers accept the last User-Agent in the header while others (e.g. Microsoft-IIS/10.0 at AWS) will return an error. Technically, it is correct to return an error if multiple User-Agents are given in the header.
Here is the relevant part of the code:
var serverIP = "www.somehost.se";
var serviceURL = "some_service";
var headerHashMap = {
'Host' : 'www.somehost.se',
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59',
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language' : 'sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding' : 'gzip, deflate',
'DNT' : '1',
'If-Modified-Since' : 'Mon, 08 Nov 2021 11:14:19 GMT',
};
var hostURL = "http://" + serverIP + "/" + serviceURL ;
console.info("url=" + hostURL);
var jsonData = actions.HTTP.sendHttpGetRequest(hostURL,headerHashMap,3000);
console.info(jsonData);
Using tcpdump and Wireshark, I have verified that two User-Agents are in fact sent from openHAB :
GET /some_service HTTP/1.1
Accept-Encoding: gzip
**User-Agent: Jetty/9.4.46.v20220331**
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
**User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59**
If-Modified-Since: Mon, 08 Nov 2021 11:14:19 GMT
Host: www.somehost.se
Accept-Encoding: gzip, deflate
DNT: 1
Accept-Language: sv-SE,sv;q=0.8,en-US;q=0.5,en;q=0.3
If I remove the User-Agent string from the hashmap, everything works fine except that the server of course returns a response for a Jetty client rather than the Mozilla/5.0 I was trying to get.
I have tried to find information in the documentation for sendHttpGetRequest that indicates that the content of the header is not handled but found nothing.
(I have tried http as well as https - no difference. The example is edited to hide the specific server/service)
Any clue as to what is going on here?