| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e592c32 commit 98b9705
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -184,7 +184,7 @@ E('ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND', | |||
| 184 | 184 | E('ERR_HTTP2_INFO_STATUS_NOT_ALLOWED', | |
| 185 | 185 | 'Informational status codes cannot be used'); | |
| 186 | 186 | E('ERR_HTTP2_INVALID_CONNECTION_HEADERS', | |
| 187 | - 'HTTP/1 Connection specific headers are forbidden'); | ||
| 187 | + 'HTTP/1 Connection specific headers are forbidden: "%s"'); | ||
| 188 | 188 | E('ERR_HTTP2_INVALID_HEADER_VALUE', 'Value must not be undefined or null'); | |
| 189 | 189 | E('ERR_HTTP2_INVALID_INFO_STATUS', | |
| 190 | 190 | (code) => `Invalid informational status code: ${code}`); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -399,10 +399,10 @@ function mapToHeaders(map, | |||
| 399 | 399 | for (var i = 0; i < keys.length; i++) { | |
| 400 | 400 | let key = keys[i]; | |
| 401 | 401 | let value = map[key]; | |
| 402 | - let val; | ||
| 403 | - if (typeof key === 'symbol' || value === undefined || !key) | ||
| 402 | + if (value === undefined || key === '') | ||
| 404 | 403 | continue; | |
| 405 | - key = String(key).toLowerCase(); | ||
| 404 | + key = key.toLowerCase(); | ||
| 405 | + const isSingleValueHeader = kSingleValueHeaders.has(key); | ||
| 406 | 406 | let isArray = Array.isArray(value); | |
| 407 | 407 | if (isArray) { | |
| 408 | 408 | switch (value.length) { | |
@@ -413,34 +413,35 @@ function mapToHeaders(map, | |||
| 413 | 413 | isArray = false; | |
| 414 | 414 | break; | |
| 415 | 415 | default: | |
| 416 | - if (kSingleValueHeaders.has(key)) | ||
| 416 | + if (isSingleValueHeader) | ||
| 417 | 417 | return new errors.Error('ERR_HTTP2_HEADER_SINGLE_VALUE', key); | |
| 418 | 418 | } | |
| 419 | + } else { | ||
| 420 | + value = String(value); | ||
| 421 | + } | ||
| 422 | + if (isSingleValueHeader) { | ||
| 423 | + if (singles.has(key)) | ||
| 424 | + return new errors.Error('ERR_HTTP2_HEADER_SINGLE_VALUE', key); | ||
| 425 | + singles.add(key); | ||
| 419 | 426 | } | |
| 420 | 427 | if (key[0] === ':') { | |
| 421 | 428 | const err = assertValuePseudoHeader(key); | |
| 422 | 429 | if (err !== undefined) | |
| 423 | 430 | return err; | |
| 424 | - ret = `${key}\0${String(value)}\0${ret}`; | ||
| 431 | + ret = `${key}\0${value}\0${ret}`; | ||
| 425 | 432 | count++; | |
| 426 | 433 | } else { | |
| 427 | - if (kSingleValueHeaders.has(key)) { | ||
| 428 | - if (singles.has(key)) | ||
| 429 | - return new errors.Error('ERR_HTTP2_HEADER_SINGLE_VALUE', key); | ||
| 430 | - singles.add(key); | ||
| 431 | - } | ||
| 432 | 434 | if (isIllegalConnectionSpecificHeader(key, value)) { | |
| 433 | - return new errors.Error('ERR_HTTP2_INVALID_CONNECTION_HEADERS'); | ||
| 435 | + return new errors.Error('ERR_HTTP2_INVALID_CONNECTION_HEADERS', key); | ||
| 434 | 436 | } | |
| 435 | 437 | if (isArray) { | |
| 436 | 438 | for (var k = 0; k < value.length; k++) { | |
| 437 | - val = String(value[k]); | ||
| 439 | + const val = String(value[k]); | ||
| 438 | 440 | ret += `${key}\0${val}\0`; | |
| 439 | 441 | } | |
| 440 | 442 | count += value.length; | |
| 441 | 443 | } else { | |
| 442 | - val = String(value); | ||
| 443 | - ret += `${key}\0${val}\0`; | ||
| 444 | + ret += `${key}\0${value}\0`; | ||
| 444 | 445 | count++; | |
| 445 | 446 | } | |
| 446 | 447 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ server.on('stream', common.mustCall((stream, headers) => { | |||
| 32 | 32 | () => stream.pushStream({ 'connection': 'test' }, {}, () => {}), | |
| 33 | 33 | { | |
| 34 | 34 | code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', | |
| 35 | - message: 'HTTP/1 Connection specific headers are forbidden' | ||
| 35 | + message: 'HTTP/1 Connection specific headers are forbidden: "connection"' | ||
| 36 | 36 | } | |
| 37 | 37 | ); | |
| 38 | 38 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,14 +158,28 @@ const { | |||
| 158 | 158 | // Arrays containing a single set-cookie value are handled correctly | |
| 159 | 159 | // (https://github.com/nodejs/node/issues/16452) | |
| 160 | 160 | const headers = { | |
| 161 | - 'set-cookie': 'foo=bar' | ||
| 161 | + 'set-cookie': ['foo=bar'] | ||
| 162 | 162 | }; | |
| 163 | 163 | assert.deepStrictEqual( | |
| 164 | 164 | mapToHeaders(headers), | |
| 165 | 165 | [ [ 'set-cookie', 'foo=bar', '' ].join('\0'), 1 ] | |
| 166 | 166 | ); | |
| 167 | 167 | } | |
| 168 | 168 | ||
| 169 | + { | ||
| 170 | + // pseudo-headers are only allowed a single value | ||
| 171 | + const headers = { | ||
| 172 | + ':status': 200, | ||
| 173 | + ':statuS': 204, | ||
| 174 | + }; | ||
| 175 | + | ||
| 176 | + common.expectsError({ | ||
| 177 | + code: 'ERR_HTTP2_HEADER_SINGLE_VALUE', | ||
| 178 | + type: Error, | ||
| 179 | + message: 'Header field ":status" must have only a single value' | ||
| 180 | + })(mapToHeaders(headers)); | ||
| 181 | + } | ||
| 182 | + | ||
| 169 | 183 | // The following are not allowed to have multiple values | |
| 170 | 184 | [ | |
| 171 | 185 | HTTP2_HEADER_STATUS, | |
@@ -248,8 +262,6 @@ const { | |||
| 248 | 262 | assert(!(mapToHeaders({ [name]: [1, 2, 3] }) instanceof Error), name); | |
| 249 | 263 | }); | |
| 250 | 264 | ||
| 251 | - const regex = | ||
| 252 | - /^HTTP\/1 Connection specific headers are forbidden$/; | ||
| 253 | 265 | [ | |
| 254 | 266 | HTTP2_HEADER_CONNECTION, | |
| 255 | 267 | HTTP2_HEADER_UPGRADE, | |
@@ -269,18 +281,21 @@ const regex = | |||
| 269 | 281 | ].forEach((name) => { | |
| 270 | 282 | common.expectsError({ | |
| 271 | 283 | code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', | |
| 272 | - message: regex | ||
| 284 | + message: 'HTTP/1 Connection specific headers are forbidden: ' + | ||
| 285 | + `"${name.toLowerCase()}"` | ||
| 273 | 286 | })(mapToHeaders({ [name]: 'abc' })); | |
| 274 | 287 | }); | |
| 275 | 288 | ||
| 276 | 289 | common.expectsError({ | |
| 277 | 290 | code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', | |
| 278 | - message: regex | ||
| 291 | + message: 'HTTP/1 Connection specific headers are forbidden: ' + | ||
| 292 | + `"${HTTP2_HEADER_TE}"` | ||
| 279 | 293 | })(mapToHeaders({ [HTTP2_HEADER_TE]: ['abc'] })); | |
| 280 | 294 | ||
| 281 | 295 | common.expectsError({ | |
| 282 | 296 | code: 'ERR_HTTP2_INVALID_CONNECTION_HEADERS', | |
| 283 | - message: regex | ||
| 297 | + message: 'HTTP/1 Connection specific headers are forbidden: ' + | ||
| 298 | + `"${HTTP2_HEADER_TE}"` | ||
| 284 | 299 | })(mapToHeaders({ [HTTP2_HEADER_TE]: ['abc', 'trailers'] })); | |
| 285 | 300 | ||
| 286 | 301 | assert(!(mapToHeaders({ te: 'trailers' }) instanceof Error)); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments