Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
502e14b
add headers impl
Ethan-Arrowood Jun 10, 2021
b0f9a75
update headers and begin porting tests
Ethan-Arrowood Jun 10, 2021
499c1c6
add in progress test script
Ethan-Arrowood Jun 15, 2021
357ba5d
complete test migration
Ethan-Arrowood Jun 21, 2021
b34a484
add docs
Ethan-Arrowood Jun 21, 2021
f8f2059
fix ordering
Ethan-Arrowood Jun 21, 2021
b585716
lint fixes
Ethan-Arrowood Jun 21, 2021
865d422
Update doc/api/fetch.md
Ethan-Arrowood Jun 21, 2021
c96bf21
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
e7413b1
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
4d96cf4
Update test/parallel/test-headers.js
Ethan-Arrowood Jun 21, 2021
6b726a9
Update test/parallel/test-headers.js
Ethan-Arrowood Jun 21, 2021
c735d9e
use entries for iterator
Ethan-Arrowood Jun 21, 2021
173ccef
lint md
Ethan-Arrowood Jun 21, 2021
d856bd4
fix lint again
Ethan-Arrowood Jun 21, 2021
bed131e
add missing character
Ethan-Arrowood Jun 21, 2021
a87342f
Update doc/api/fetch.md
Ethan-Arrowood Jun 21, 2021
71c1aa2
Update doc/api/fetch.md
Ethan-Arrowood Jun 21, 2021
d5e3df3
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
c8d156a
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
8fdd64c
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
d66e313
fix lint and tests
Ethan-Arrowood Jun 21, 2021
1d042f0
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
0a58d93
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jun 21, 2021
a85b1c0
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jul 22, 2021
58da701
incorporate review and fix failing test
Ethan-Arrowood Jul 22, 2021
92b9519
export api
Ethan-Arrowood Jul 22, 2021
ce73c08
Merge branch 'master' into feature/fetch-headers
Ethan-Arrowood Jul 22, 2021
6f212c0
add inspect and docs
Ethan-Arrowood Jul 22, 2021
6f06698
Update lib/fetch.js
Ethan-Arrowood Jul 26, 2021
ae223ca
Update lib/fetch.js
Ethan-Arrowood Jul 26, 2021
1ef66a0
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jul 26, 2021
a9a7b4d
Update lib/internal/fetch/headers.js
Ethan-Arrowood Jul 26, 2021
3b902a1
incorporate review changes
Ethan-Arrowood Jul 26, 2021
1568b7c
Merge branch 'master' into feature/fetch-headers
Ethan-Arrowood Jul 26, 2021
cd38842
lint fixes
Ethan-Arrowood Jul 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
complete test migration
  • Loading branch information
Ethan-Arrowood committed Jun 21, 2021
commit 357ba5dc1bc0cbbdeee5d4ea89f64e49b455a63f
7 changes: 3 additions & 4 deletions lib/internal/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ const {
} = primordials;

const { validateObject } = require('internal/validators');

const { isBoxedPrimitive } = require('internal/util/types');

const { validateHeaderName, validateHeaderValue } = require('_http_outgoing');

const { Buffer } = require('buffer');
const console = require('console');

const kHeadersList = Symbol('headers list');

Expand All @@ -35,7 +33,7 @@ const kHeadersList = Symbol('headers list');
*/
function binarySearch(arr, val) {
let low = 0;
let high = arr.length / 2;
let high = Math.floor(arr.length / 2);

while (high > low) {
const mid = (high + low) >>> 1;
Expand Down Expand Up @@ -208,5 +206,6 @@ class Headers {

module.exports = {
Headers,
kHeadersList
kHeadersList,
binarySearch
Comment thread
Ethan-Arrowood marked this conversation as resolved.
Outdated
};
194 changes: 193 additions & 1 deletion test/parallel/test-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const assert = require('assert');

// Flags: --expose-internals

const { Headers, kHeadersList } = require('internal/fetch/headers');
const { Headers, kHeadersList, binarySearch } = require('internal/fetch/headers');

{
// init is undefined
Expand Down Expand Up @@ -181,4 +181,196 @@ const { Headers, kHeadersList } = require('internal/fetch/headers');
assert.throws(() => {
headers.get('invalid @ header ?')
})
}

{
// has
const headers = new Headers();
headers.append('test-name-1', 'test-value-1');
headers.append('test-name-2', 'test-value-2');
headers.append('test-name-3', 'test-value-3');
assert.strictEqual(headers.has('test-name-1'), true);
assert.strictEqual(headers.has('does-not-exist'), false);

assert.throws(() => {
headers.has()
})

assert.throws(() => {
headers.has('invalid @ header ?')
})
}

{
// set
const headers = new Headers();
headers.set('test-name-1', 'test-value-1');
assert.deepStrictEqual(headers[kHeadersList], [
'test-name-1',
'test-value-1',
]);
headers.set('test-name-2', 'test-value-2');
assert.deepStrictEqual(headers[kHeadersList], [
'test-name-1',
'test-value-1',
'test-name-2',
'test-value-2',
]);
headers.set('test-name-1', 'test-value-3');
assert.deepStrictEqual(headers[kHeadersList], [
'test-name-1',
'test-value-3',
'test-name-2',
'test-value-2',
]);

assert.throws(() => {
headers.set();
});

assert.throws(() => {
headers.set('test-name');
});

assert.throws(() => {
headers.set('invalid @ header ? name', 'test-value');
});
}

{
// for each
const init = [
['a', '1'],
['b', '2'],
['c', '3'],
['abc', '4'],
['b', '5']
]
const expected = [
['a', '1'],
['abc', '4'],
['b', '2, 5'],
['c', '3']
]

const headers = new Headers(init)
const that = {}
let i = 0
headers.forEach(function (value, key, _headers) {
assert.deepStrictEqual(expected[i++], [key, value])
assert.strictEqual(headers, _headers)
assert.strictEqual(this, that)
}, that)
}

{
// entries
const init = [
['a', '1'],
['b', '2'],
['c', '3'],
['abc', '4'],
['b', '5']
]
const expected = [
['a', '1'],
['abc', '4'],
['b', '2, 5'],
['c', '3']
]
const headers = new Headers(init)
let i = 0
for (const header of headers.entries()) {
assert.deepStrictEqual(header, expected[i++])
}
}

{
// keys
const init = [
['a', '1'],
['b', '2'],
['c', '3'],
['abc', '4'],
['b', '5']
]
const expected = ['a', 'abc', 'b', 'c']
const headers = new Headers(init)
let i = 0
for (const key of headers.keys()) {
assert.deepStrictEqual(key, expected[i++])
}
}

{
// values
const init = [
['a', '1'],
['b', '2'],
['c', '3'],
['abc', '4'],
['b', '5']
]
const expected = ['1', '4', '2, 5', '3']
const headers = new Headers(init)
let i = 0
for (const value of headers.values()) {
assert.deepStrictEqual(value, expected[i++])
}
}

{
// for of
const init = [
['a', '1'],
['b', '2'],
['c', '3'],
['abc', '4'],
['b', '5']
]
const expected = [
['a', '1'],
['abc', '4'],
['b', '2, 5'],
['c', '3']
]
let i = 0
const headers = new Headers(init)
for (const header of headers) {
assert.deepStrictEqual(header, expected[i++])
}
}

{
// 0 1 2 3 4 5 6 7
const l1 = ['b', 1, 'c', 2, 'd', 3, 'f', 4]
// 0 1 2 3 4 5 6 7 8 9
const l2 = ['b', 1, 'c', 2, 'd', 3, 'e', 4, 'g', 5]
// 0 1 2 3 4 5 6 7
const l3 = ['a', 1, 'b', 2, 'bcd', 3, 'c', 4]
// 0 1 2 3 4 5 6 7 8 9
const l4 = ['a', 1, 'b', 2, 'c', 3, 'cde', 4, 'f', 5]

const tests = [
{ input: [l1, 'c'], expected: 2, message: 'find item in n=even array' },
{ input: [l1, 'f'], expected: 6, message: 'find item at end of n=even array' },
{ input: [l1, 'b'], expected: 0, message: 'find item at beg of n=even array' },
{ input: [l1, 'e'], expected: 6, message: 'find new item position in n=even array' },
{ input: [l1, 'g'], expected: 8, message: 'find new item position at end of n=even array' },
{ input: [l1, 'a'], expected: 0, message: 'find new item position at beg of n=even array' },
{ input: [l2, 'c'], expected: 2, message: 'find item in n=odd array' },
{ input: [l2, 'g'], expected: 8, message: 'find item at end of n=odd array' },
{ input: [l2, 'b'], expected: 0, message: 'find item at beg of n=odd array' },
{ input: [l2, 'f'], expected: 8, message: 'find new item position in n=odd array' },
{ input: [l2, 'h'], expected: 10, message: 'find new item position at end of n=odd array' },
{ input: [l2, 'a'], expected: 0, message: 'find new item position at beg of n=odd array' },
{ input: [l3, 'b'], expected: 2, message: 'find item with similarity in n=odd array' },
{ input: [l3, 'bcd'], expected: 4, message: 'find item with similarity in n=odd array' },
{ input: [l4, 'c'], expected: 4, message: 'find item with similarity in n=odd array' },
{ input: [l4, 'cde'], expected: 6, message: 'find item with similarity in n=odd array' }
]

tests.forEach(({ input: [list, target], expected, message }) => {
assert.deepStrictEqual(expected, binarySearch(list, target), message)
})
}
Comment thread
Ethan-Arrowood marked this conversation as resolved.
Outdated