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

Remove header sorting when iterates over it #1662

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/headers.js
Expand Up @@ -105,7 +105,7 @@ export default class Headers extends URLSearchParams {

super(result);

// Returning a Proxy that will lowercase key names, validate parameters and sort keys
// Returning a Proxy that will lowercase key names, validate parameters
// eslint-disable-next-line no-constructor-return
return new Proxy(this, {
get(target, p, receiver) {
Expand Down Expand Up @@ -135,7 +135,6 @@ export default class Headers extends URLSearchParams {

case 'keys':
return () => {
target.sort();
return new Set(URLSearchParams.prototype.keys.call(target)).keys();
};

Expand Down
19 changes: 9 additions & 10 deletions test/headers.js
Expand Up @@ -47,9 +47,9 @@ describe('Headers', () => {
}

expect(result).to.deep.equal([
['a', '1'],
['b', '2, 3'],
['c', '4']
['c', '4'],
['a', '1'],
]);
});

Expand Down Expand Up @@ -99,9 +99,9 @@ describe('Headers', () => {
}

expect(result).to.deep.equal([
['a', '1'],
['b', '2, 3'],
['c', '4']
['c', '4'],
['a', '1'],
]);
});

Expand All @@ -115,9 +115,9 @@ describe('Headers', () => {

expect(headers.entries()).to.be.iterable
.and.to.deep.iterate.over([
['a', '1'],
['b', '2, 3'],
['c', '4']
['c', '4'],
['a', '1'],
]);
});

Expand All @@ -130,7 +130,7 @@ describe('Headers', () => {
headers.append('b', '3');

expect(headers.keys()).to.be.iterable
.and.to.iterate.over(['a', 'b', 'c']);
.and.to.iterate.over(['b', 'c', 'a']);
});

it('should allow iterating through all headers with values()', () => {
Expand All @@ -142,7 +142,7 @@ describe('Headers', () => {
headers.append('b', '3');

expect(headers.values()).to.be.iterable
.and.to.iterate.over(['1', '2, 3', '4']);
.and.to.iterate.over(['2, 3', '4', '1']);
});

it('should reject illegal header', () => {
Expand Down Expand Up @@ -273,6 +273,5 @@ describe('Headers', () => {
]);

// eslint-disable-next-line quotes
expect(format(headers)).to.equal("{ a: [ '1', '3' ], b: '2', host: 'thehost' }");
});
expect(format(headers)).to.equal("{ host: 'thehost', a: [ '1', '3' ], b: '2' }"); });
});