AnWeber / vscode-httpyac

Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT and WebSocket requests directly within Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=anweber.vscode-httpyac
MIT License
237 stars 20 forks source link

Specifying HTTPS #168

Closed asherber closed 1 year ago

asherber commented 1 year ago

This HTTP file correctly sends via HTTPS:

@host = https://foo.com

GET /

But if I use httpyac's "generate code" feature, I get:

GET / HTTP/1.1
Host: foo.com

And if I send that request, it goes via HTTP. 

AnWeber commented 1 year ago

Is there a way to specify HTTPS in a raw file like this?

Append Port 443 to the host header. See https://github.com/AnWeber/httpyac/blob/main/src/plugins/core/replacer/hostVariableReplacer.ts#L13

Should the generated code give the whole URL on the first line, so that it includes the https?

I use httpsnippet to generate the http language code. Actually, I want to stick to their default. It would be possible that I create the code snippet myself, based on the executed request object. Imho it seems to be a bug that port 443 is not appended on host header if https is used (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host).

You could build a workaround so that https is always used for this case. Just create a .httpyac.js file in the root of the project.

module.exports = {
  configureHooks(api) {
    api.hooks.replaceVariable.addHook('httpsHost', async function (text, type, { request }) {
      if (typeof text === "string" && type === "url" && text.startsWith('/')) {
        const host = utils.getHeader(request?.headers, 'Host');
        return `https://${host}${text}`;
      }
      return text;
    }, { before: ['host'] });
  }
}
asherber commented 1 year ago

Thanks!