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

Setting Scheme and Host in headers? #547

Open
huangjj27 opened this issue May 1, 2022 · 7 comments
Open

Setting Scheme and Host in headers? #547

huangjj27 opened this issue May 1, 2022 · 7 comments
Labels
enhancement New feature or request topic: request

Comments

@huangjj27
Copy link

huangjj27 commented May 1, 2022

I'm using hurl as RESTful API specification, so I prefer a format that only the API path after the HTTP action, while the scheme and the host are defined in a Scheme and a Host header:

# token.hurl
POST /tokens
Scheme: {{SCHEME}}
Host: {{HOST}}

But when I run this example with the command hurl tokens.hurl --variables-file=test.env, I get this error:

> hurl tokens.hurl --variables-file=test.env
error: Http Connection
  --> tokens.hurl:8:6
   |
 8 | POST /tokens
   |      ^^^^^^^ (3) URL using bad/illegal format or missing URL
   |

And I expect the example should work, but it seems this doesn't work now. Therefore, I'm here to request new feature support. Any advice?

@huangjj27 huangjj27 changed the title Can hurl pass only the "url-path" part when with a Host Can hurl pass only the "url-path" part when with a Host Header? May 1, 2022
@jcamiel
Copy link
Collaborator

jcamiel commented May 1, 2022

Hi,

Using url without scheme (http/https) and host looks really like HTTP so it' interesting. But how would you tell if the protocol is HTTP or HTTPS? Choosing one by default seems arbitrary...

For the moment, you can, of course, templatize the url:

POST https://{{host}}/tokens

@huangjj27
Copy link
Author

huangjj27 commented May 2, 2022

But how would you tell if the protocol is HTTP or HTTPS?

Oh, Indeed that variable {{host}} means {{scheme_and_host}}, so that I could use HTTP for the test environment and HTTPS for production. Besides, it's set as the "Host" header. I check out the section-5.4 of RFC 7230, and find out that the Host header doesn't contain a scheme. A temporary solution is to place the {{scheme_and_host}} variable into the URL rather than the Host header, like:

# token.hurl
POST {{scheme_and_host}}/tokens

where {{scheme_and_host}} could be a http://my.domain.test or a https://my.domain.release

@huangjj27
Copy link
Author

I find some interesting request from firefox, that some request is using a Scheme header to identify the request scheme, It this part of the HTTP protocol standard?

@huangjj27 huangjj27 changed the title Can hurl pass only the "url-path" part when with a Host Header? Setting Scheme and Host in headers? May 2, 2022
@huangjj27
Copy link
Author

The original post is edited.

@jcamiel
Copy link
Collaborator

jcamiel commented May 2, 2022

I'm not at all a HTTP spec expert but I don't see the Scheme header often. It's not referenced in RFC2616 nor in https://en.wikipedia.org/wiki/List_of_HTTP_header_fields. As it is not "well known", I'm a bit reluctant to add this kind of syntax:

POST /path
Host: example.com
Scheme: https

@huangjj27
Copy link
Author

It's not referenced in RFC2616 nor in https://en.wikipedia.org/wiki/List_of_HTTP_header_fields.

ok, since Scheme is not a standard header, we should not parse it as a header.

@louy2
Copy link

louy2 commented Feb 5, 2024

I really like this idea of making the request line more like actual HTTP request.

how would you tell if the protocol is HTTP or HTTPS?

When a URL has no protocol, curl follows the option --proto-default, or in its absence guesses the protocol based on the hostname. You can also specify --ssl-reqd to force TLS upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic: request
Projects
None yet
Development

No branches or pull requests

3 participants