| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,10 +102,21 @@ function ClientRequest(options, cb) { | |||
| 102 | 102 | self.socketPath = options.socketPath; | |
| 103 | 103 | self.timeout = options.timeout; | |
| 104 | 104 | ||
| 105 | - var method = self.method = (options.method || 'GET').toUpperCase(); | ||
| 106 | - if (!common._checkIsHttpToken(method)) { | ||
| 107 | - throw new TypeError('Method must be a valid HTTP token'); | ||
| 105 | + var method = options.method; | ||
| 106 | + var methodIsString = (typeof method === 'string'); | ||
| 107 | + if (method != null && !methodIsString) { | ||
| 108 | + throw new TypeError('Method must be a string'); | ||
| 108 | 109 | } | |
| 110 | + | ||
| 111 | + if (methodIsString && method) { | ||
| 112 | + if (!common._checkIsHttpToken(method)) { | ||
| 113 | + throw new TypeError('Method must be a valid HTTP token'); | ||
| 114 | + } | ||
| 115 | + method = self.method = method.toUpperCase(); | ||
| 116 | + } else { | ||
| 117 | + method = self.method = 'GET'; | ||
| 118 | + } | ||
| 119 | + | ||
| 109 | 120 | self.path = options.path || '/'; | |
| 110 | 121 | if (cb) { | |
| 111 | 122 | self.once('response', cb); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -265,8 +265,6 @@ var validTokens = [ | |||
| 265 | 265 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // ... 255 | |
| 266 | 266 | ]; | |
| 267 | 267 | function checkIsHttpToken(val) { | |
| 268 | - if (typeof val !== 'string' || val.length === 0) | ||
| 269 | - return false; | ||
| 270 | 268 | if (!validTokens[val.charCodeAt(0)]) | |
| 271 | 269 | return false; | |
| 272 | 270 | if (val.length < 2) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,18 +319,18 @@ function _storeHeader(firstLine, headers) { | |||
| 319 | 319 | if (state.sentExpect) this._send(''); | |
| 320 | 320 | } | |
| 321 | 321 | ||
| 322 | - function storeHeader(self, state, field, value) { | ||
| 323 | - if (!checkIsHttpToken(field)) { | ||
| 322 | + function storeHeader(self, state, key, value) { | ||
| 323 | + if (typeof key !== 'string' || !key || !checkIsHttpToken(key)) { | ||
| 324 | 324 | throw new TypeError( | |
| 325 | - 'Header name must be a valid HTTP Token ["' + field + '"]'); | ||
| 325 | + 'Header name must be a valid HTTP Token ["' + key + '"]'); | ||
| 326 | 326 | } | |
| 327 | 327 | if (checkInvalidHeaderChar(value)) { | |
| 328 | - debug('Header "%s" contains invalid characters', field); | ||
| 328 | + debug('Header "%s" contains invalid characters', key); | ||
| 329 | 329 | throw new TypeError('The header content contains invalid characters'); | |
| 330 | 330 | } | |
| 331 | - state.messageHeader += field + ': ' + escapeHeaderValue(value) + CRLF; | ||
| 331 | + state.messageHeader += key + ': ' + escapeHeaderValue(value) + CRLF; | ||
| 332 | 332 | ||
| 333 | - if (connectionExpression.test(field)) { | ||
| 333 | + if (connectionExpression.test(key)) { | ||
| 334 | 334 | state.sentConnectionHeader = true; | |
| 335 | 335 | if (connCloseExpression.test(value)) { | |
| 336 | 336 | self._last = true; | |
@@ -339,26 +339,26 @@ function storeHeader(self, state, field, value) { | |||
| 339 | 339 | } | |
| 340 | 340 | if (connUpgradeExpression.test(value)) | |
| 341 | 341 | state.sentConnectionUpgrade = true; | |
| 342 | - } else if (transferEncodingExpression.test(field)) { | ||
| 342 | + } else if (transferEncodingExpression.test(key)) { | ||
| 343 | 343 | state.sentTransferEncodingHeader = true; | |
| 344 | 344 | if (trfrEncChunkExpression.test(value)) self.chunkedEncoding = true; | |
| 345 | 345 | ||
| 346 | - } else if (contentLengthExpression.test(field)) { | ||
| 346 | + } else if (contentLengthExpression.test(key)) { | ||
| 347 | 347 | state.sentContentLengthHeader = true; | |
| 348 | - } else if (dateExpression.test(field)) { | ||
| 348 | + } else if (dateExpression.test(key)) { | ||
| 349 | 349 | state.sentDateHeader = true; | |
| 350 | - } else if (expectExpression.test(field)) { | ||
| 350 | + } else if (expectExpression.test(key)) { | ||
| 351 | 351 | state.sentExpect = true; | |
| 352 | - } else if (trailerExpression.test(field)) { | ||
| 352 | + } else if (trailerExpression.test(key)) { | ||
| 353 | 353 | state.sentTrailer = true; | |
| 354 | - } else if (upgradeExpression.test(field)) { | ||
| 354 | + } else if (upgradeExpression.test(key)) { | ||
| 355 | 355 | state.sentUpgrade = true; | |
| 356 | 356 | } | |
| 357 | 357 | } | |
| 358 | 358 | ||
| 359 | 359 | ||
| 360 | 360 | OutgoingMessage.prototype.setHeader = function setHeader(name, value) { | |
| 361 | - if (!checkIsHttpToken(name)) | ||
| 361 | + if (typeof name !== 'string' || !name || !checkIsHttpToken(name)) | ||
| 362 | 362 | throw new TypeError( | |
| 363 | 363 | 'Header name must be a valid HTTP Token ["' + name + '"]'); | |
| 364 | 364 | if (value === undefined) | |
@@ -538,7 +538,7 @@ OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { | |||
| 538 | 538 | field = key; | |
| 539 | 539 | value = headers[key]; | |
| 540 | 540 | } | |
| 541 | - if (!checkIsHttpToken(field)) { | ||
| 541 | + if (typeof field !== 'string' || !field || !checkIsHttpToken(field)) { | ||
| 542 | 542 | throw new TypeError( | |
| 543 | 543 | 'Trailer name must be a valid HTTP Token ["' + field + '"]'); | |
| 544 | 544 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments