Commit 8ba0fc7
authored
feat: Throw error if request headers are not an object (#1574)
Throw if headersFieldNamesToLowerCase is not provided an object.
Adds a test to cover the exception case.
Going through the git history for this function, all the way back to
when it was added with 4048734, I can't find a case where a non-object
input was valid.
Once PR # 1564 is merged in, this utility will only be called in two
places:
- Creating an Interceptor if the Scope was created with `options`
- When http.request is called with an `options` object
In both places, providing defined, but non-object values causes chaos.
If the value is a truthy, non-iterable then the header was ignored
during matching. For example, the following will match Interceptors as
if `reqheaders` had not been provided.
```js
nock('http://example.com', { reqheaders: 1 }).get('/').reply
```
However, if the value was provided as a non-plain object iterable, such
as an array or string, the header matching logic would attempt to match
header field names with numerical keys, rendering the whole Scope
useless.1 parent 1e7baa1 commit 8ba0fc7
3 files changed
+35
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
204 | 209 | | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
| 210 | + | |
| 211 | + | |
209 | 212 | | |
210 | 213 | | |
211 | | - | |
212 | | - | |
213 | 214 | | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
219 | 220 | | |
220 | 221 | | |
221 | | - | |
| 222 | + | |
222 | 223 | | |
223 | 224 | | |
224 | 225 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
29 | 40 | | |
30 | 41 | | |
31 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
369 | 380 | | |
370 | 381 | | |
371 | 382 | | |
| |||
0 commit comments