httpClientLib - Custom Header Host

Enonic version: 7.9.2

We tried to update the http-client library to the latest version (v3.1.0) in one of our projects, but we are having problems with one request that customizes the header host.

httpClientLib.request({
  url,
  headers: {
    "Host": "test.example.com"
  }
});

The request is getting the error:

restricted header name: "Host"

After some research, I found this: http2 - How to customise "host" header in Java http client - Stack Overflow
It looks like this can be solved by adding the property jdk.httpclient.allowRestrictedHeaders

Is there a way to fix this in the library?

Note: version 2.2.1 is still working correctly for this.

1 Like

The answer you found says the following:

As of Java 12 (EA build 22) it has been solved by additional property jdk.httpclient.allowRestrictedHeaders (see [JDK-8213696] Make restricted headers in HTTP Client configurable and remove Date by default - Java Bug System).

with “Java 12” being the key words.

We cannot use this fix as we are not on Java 12. If you are, you can try it yourself by forking the library repo and applying the fix as suggested. If this doesn’t work, you can downgrade to the previous version of the library that works for you.

We will meanwhile try to find alternative solution to the problem you described. Will keep you updated.

4 Likes

“jdk.httpclient.allowRestrictedHeaders” is a new system property in Java, which can be specified on XP startup: with newer XP versions that embed Java 11.0.14 and higher. For instance via setenv.sh with
-Djdk.httpclient.allowRestrictedHeaders=…” config line.

7.9.2 XP uses 11.0.15 java version, so looks like you can add the property for your current environment.

https://bugs.openjdk.org/browse/JDK-8274018

2 Likes