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

Support the special character '.' in header names #128

Closed
attilagyongyosi opened this issue Nov 26, 2021 · 9 comments
Closed

Support the special character '.' in header names #128

attilagyongyosi opened this issue Nov 26, 2021 · 9 comments

Comments

@attilagyongyosi
Copy link

attilagyongyosi commented Nov 26, 2021

Background

HTTP header field names can contain the character . according to this RFC and the definition of a token within.
However, httpyac fails to properly parse an .http file with such a header name.

Although commonly used header names have dashes, certain web services can require custom header names.
httpyac should fully support the RFC, especially for proper interoperability with the IntelliJ REST Client plugin.

Example http File

GET https://google.com
header.name: xyz

Executing httpyac with such a file, the following error report can be observed:

ExecuteHook: httpClient failed
RequestError: The `GET` method cannot be used with a body
    at Request._destroy (D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\core\index.js:1378:21)
    at _destroy (node:internal/streams/destroy:102:25)
    at Request.destroy (node:internal/streams/destroy:64:5)
    at D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\core\index.js:354:26
    at Request._finalizeBody (D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\core\index.js:716:23)
    at D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\core\index.js:333:28
    at new Request (D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\core\index.js:357:11)
    at makeRequest (D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\as-promise\index.js:35:29)
    at D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\as-promise\index.js:147:9
    at D:\projects\sandboxes\httpyac-test\node_modules\p-cancelable\index.js:63:11
    at new Promise (<anonymous>)
    at new PCancelable (D:\projects\sandboxes\httpyac-test\node_modules\p-cancelable\index.js:31:19)
    at Object.asPromise [as default] (D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\as-promise\index.js:33:21)
    at getPromiseOrStream (D:\projects\sandboxes\httpyac-test\node_modules\got\dist\source\create.js:43:121) {
  code: 'ERR_GOT_REQUEST_ERROR',
  timings: undefined
}

as the parsing of the file breaks and header.name: xyz is now considered as the request body.

@AnWeber
Copy link
Owner

AnWeber commented Nov 26, 2021

This regex is the culprit: https://github.com/AnWeber/httpyac/blob/main/src/parser/parserRegex.ts#L62. I will extend according to the RFC.

@attilagyongyosi
Copy link
Author

Hey @AnWeber, thanks for the very quick reply!
I am planning on introducing your VSCode plugin at work, but some of our services require header names with dots in them.
It would be super cool if support would be there.

@AnWeber
Copy link
Owner

AnWeber commented Nov 26, 2021

Workaround is possible using Javascript

{{
request.header['header.name'] = 'xyz';
}}
GET https://google.com
header.name: xyz

@attilagyongyosi
Copy link
Author

That is true.
That unfortunately wouldn't suffice for my situation though: as some of our engineers use WebStorm and others use VSCode, I am trying to find an interoperable solution of consuming .http files within IDEs. The syntax above is unfortunately not supported by the IntelliJ REST Client.

@AnWeber
Copy link
Owner

AnWeber commented Nov 26, 2021

Unfortunately Intellij does not support script or OAuth2. Otherwise the extension would not exist. I am still looking for the right regex and will then implement it.

@attilagyongyosi
Copy link
Author

Thank you, much appreciated!

@AnWeber
Copy link
Owner

AnWeber commented Nov 27, 2021

Here is the fieldValueRegExp used by JSDOM: https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/xhr/XMLHttpRequest-impl.js#L34.

@AnWeber
Copy link
Owner

AnWeber commented Nov 30, 2021

@attilagyongyosi I'm sorry it took so long now after all. There was unexpectedly much movement in this project the last few days. With the new version the regex was updated and headers with . are now allowed.

@AnWeber AnWeber closed this as completed Nov 30, 2021
@attilagyongyosi
Copy link
Author

@AnWeber, I am used to depending on enterprise teams, so no worries, this was quite a swift fix and release :)
Thank you very much!
I have updated the VSCode extension as well and I can verify that the issue is indeed no longer present.
You just made the life of a bunch of Hungarian engineers a bit better.

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

No branches or pull requests

2 participants