Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No HTTP (without TLS) support #29

Closed
Jolg42 opened this issue Jan 8, 2020 · 5 comments
Closed

No HTTP (without TLS) support #29

Jolg42 opened this issue Jan 8, 2020 · 5 comments
Labels
question Further information is requested

Comments

@Jolg42
Copy link

Jolg42 commented Jan 8, 2020

I used it like this:

const got = require('got');
const {request} = require('http2-wrapper');
const h2got = got.extend({request});

const currentRequestPromise = h2got.post("http://enhcvrwpf7kw6.x.pipedream.net", {
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ query: "Hello" }),
})

currentRequestPromise
      .then(({ body, json }) => {
        console.log({"body": body})
        console.log({"json": json})
      })
      .catch(error => {
        console.log({"error": error})
      })

And I found the error from the code here:

if (options.protocol && options.protocol !== 'https:') {
throw new ERR_INVALID_PROTOCOL(options.protocol, 'https:');
}

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?

@Jolg42
Copy link
Author

Jolg42 commented Jan 8, 2020

For a live version of the example code check https://runkit.com/jolg42/5e15b3136499c3001b25dd7d

@szmarczak
Copy link
Owner

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.

@szmarczak szmarczak added the question Further information is requested label Jan 8, 2020
@szmarczak szmarczak changed the title Impossible to make an HTTP request: ERR_INVALID_PROTOCOL No HTTP (without TLS) support Jan 8, 2020
@Jolg42
Copy link
Author

Jolg42 commented Jan 9, 2020

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?

@szmarczak
Copy link
Owner

Well, there is http2wrapper.auto, but you cannot integrate it with Got yet: sindresorhus/got#832

@rdadoune
Copy link

rdadoune commented Apr 20, 2021

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
})();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants