joepie91 / node-bhttp

A sane HTTP client library for Node.js with Streams2 support.
62 stars 12 forks source link

Crash on relative redirect #2

Closed garthk closed 9 years ago

garthk commented 9 years ago

Faced with a relative URI, bhttp 1.1.2 crashes with a TypeError in endsWith because prepareUrl doesn't expect urlOptions.protocol to be null.

Clients not supporting relative Location URI references were defensible while RFC2116 was current:

Location = "Location" ":" absoluteURI

… but this was a violation of Postel's Law, as browsers and search engines widely supported relative references and many servers relied upon them. (Those servers were also violating Postel's Law, just in the opposite direction.)

RFC2116 was obsoleted by RFC7231 in June 2014, baking relative URI support into the HTTP/1.1 standard:

Location = URI-reference

The field value consists of a single URI-reference. When it has the form of a relative reference (RFC3986, Section 4.2), the final value is computed by resolving it against the effective request URI (RFC3986, Section 5).

garthk commented 9 years ago

Trace as requested:

TypeError: Cannot read property 'length' of null
    at S.endsWith (/tmp/node_modules/bhttp/node_modules/string/lib/string.js:167:24)
    at S.chompRight (/tmp/node_modules/bhttp/node_modules/string/lib/string.js:104:16)
    at /tmp/node_modules/bhttp/lib/bhttp.js:183:47
    at tryCatcher (/tmp/node_modules/bluebird/js/main/util.js:24:31)
    at Function.Promise.attempt.Promise.try (/tmp/node_modules/bluebird/js/main/method.js:31:24)
    at prepareUrl (/tmp/node_modules/bhttp/lib/bhttp.js:172:24)
    at /tmp/node_modules/bhttp/lib/bhttp.js:364:16
    at tryCatcher (/tmp/node_modules/bluebird/js/main/util.js:24:31)
    at Promise._settlePromiseFromHandler (/tmp/node_modules/bluebird/js/main/promise.js:452:31)
    at Promise._settlePromiseAt (/tmp/node_modules/bluebird/js/main/promise.js:530:18)
    at Promise._settlePromises (/tmp/node_modules/bluebird/js/main/promise.js:646:14)
    at Async._drainQueue (/tmp/node_modules/bluebird/js/main/async.js:132:16)
    at Async._drainQueues (/tmp/node_modules/bluebird/js/main/async.js:142:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/tmp/node_modules/bluebird/js/main/async.js:16:14)
    at processImmediate [as _immediateCallback] (timers.js:358:17)
joepie91 commented 9 years ago

Fixed in v1.1.3 (9ebbc7d98ca1adc1aa5b02fa117a89e2fd262aae).