Closed Jolg42 closed 4 years ago
For a live version of the example code check https://runkit.com/jolg42/5e15b3136499c3001b25dd7d
As http is mentioned in the README I thought it would be possible but it looks like https is required. Is there a reason for that?
If you specify a request
option, it will NOT automatically detect the protocol. HTTP/2 without TLS is possible, but it is not recommended. It is also disabled in this project to prevent some inconsistencies.
The integration with Got is still WIP. Yep, there will be automatic protocol detection.
Thank you for the fast answer :)
I just tried
h2got.post("http://enhcvrwpf7kw6.x.pipedream.net", {
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: "Hello" }),
protocol: "http:"
})
And got Object {error: RequestError: Protocol "http:" not supported. Expected "https:"}
So indeed it not yet possible to use http.
I think it would be great to add it, I'm aware that https is recommended but it is not applicable in my case.
Do you know where someone should start investigating in the project to add the feature maybe?
Well, there is http2wrapper.auto
, but you cannot integrate it with Got yet: https://github.com/sindresorhus/got/pull/832
I'm also looking for HTTP/2 support without TLS. So far, the only way I can get it working with got
is by setting the h2session
and then lying about the protocol
. Our internal services use H2 without TLS for performance reasons, and it's not necessary since it's within a private VPC. This way hacky, but I need a session pool for performance reasons.
import got from 'got';
import http2 from 'http2-wrapper';
const session = http2.connect('http://internal-dns.com');
(async () => {
const response = await got('http://internal-dns.com/internal-endpoint', {
request: http2.request,
protocol: 'https:',
h2session: session,
});
console.log(response.httpVersionMajor);
// -> 2
})();
I used it like this:
And I found the error from the code here: https://github.com/szmarczak/http2-wrapper/blob/842ce093b6e839fecbb3b188d33a8d240cf8f7a5/source/client-request.js#L76-L78
As http is mentioned in the README I thought it would be possible but it looks like https is required. Is there a reason for that?