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

fix: change LF to CRLF symbol in getAllResponseHeaders facade's method #163

Merged
merged 5 commits into from
May 6, 2023
Merged

fix: change LF to CRLF symbol in getAllResponseHeaders facade's method #163

merged 5 commits into from
May 6, 2023

Conversation

avivasyuta
Copy link
Contributor

@avivasyuta avivasyuta commented May 6, 2023

Hello.

The documentation defines that the getAllResponseHeaders method of XMLHttpRequest should return all the response headers, separated by CRLF. In xhook facade implements LF separator instead of CRLF.

It breaks scripts that manually try to parse the header string received from the method getAllResponseHeaders.

Example

const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts/2', true);
xhr.send(null);
xhr.onreadystatechange = () => {
    if (xhr.readyState === 4) {
        const headers = xhr.getAllResponseHeaders()
        const arrayHeaders = headers.split('\r\n')
    }
}

Output

["cache-control:\tmax-age=43200\ncontent-type:\tapplication/json; charset=utf-8\nexpires:\t-1\npragma:\tno-cache\n"]

This code will generate an array of headers that has only one element. So I made a PR with changes that fix this issue.
It will be great if you can check it out.

@jpillora
Copy link
Owner

jpillora commented May 6, 2023

Can you plz prettier these files using our prettier config

Run npx prettier --check .
Checking formatting...
[warn] src/misc/headers.js
[warn] tests/convert.spec.ts
[warn] tests/modify-headers.spec.ts
[warn] Code style issues found in 3 files. Forgot to run Prettier?
Error: Process completed with exit code 1.

Other than that, looks like a reasonable change :) though I'll leave this one to @TrickyPi to decide

@jpillora
Copy link
Owner

jpillora commented May 6, 2023

Sorry! @TrickyPi setup CI - hopefully he can help :)

@avivasyuta
Copy link
Contributor Author

avivasyuta commented May 6, 2023

@jpillora unfortunately I cannot understand why prettier checks in CI and locally are different. I have such output :)

npx prettier --check .         
Checking formatting...
All matched files use Prettier code style!

@TrickyPi
Copy link
Collaborator

TrickyPi commented May 6, 2023

I'll take a look.

@avivasyuta
Copy link
Contributor Author

I'll take a look.

I realized that I had different version of prettier. Tell me please how I can find out what specific problems are in the files.

@TrickyPi
Copy link
Collaborator

TrickyPi commented May 6, 2023

@avivasyuta Could you try to run npx prettier --write .?

@avivasyuta
Copy link
Contributor Author

@avivasyuta Could you try to run npx prettier --write .?

done ✅

@TrickyPi TrickyPi merged commit 8853473 into jpillora:main May 6, 2023
@avivasyuta
Copy link
Contributor Author

@TrickyPi could you publish new version of lib?

@TrickyPi
Copy link
Collaborator

TrickyPi commented May 6, 2023

I published v1.6.0 to npm. But the github publish failed, maybe I need to publish manually.

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

Successfully merging this pull request may close these issues.

3 participants