Skip to content
Myr

Fix req.protocol for proxy-direct connections

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fixes #2252

authored by Ashley Streb · committed by Douglas Christopher Wilson · parent 3fc8dc5 · Browse files · 3 files+24 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+24 added−5 removed

  • tests:+15 added−0 removed
  • other:+9 added−5 removed

3 files+24 added−5 removed

modified:lib/request.js+8 added-5 removed
339 unmodified lines
340/**341 * Return the protocol string "http" or "https"342 * when requested with TLS. When the "trust proxy"343 * setting trusts the socket address, the344 * "X-Forwarded-Proto" header field will be trusted.344 * "X-Forwarded-Proto" header field will be trusted345 * and used if present.346 *347 * If you're running behind a reverse proxy that348 * supplies https for you this may be enabled.349 *350 * @return {String}351 * @api public352 */353354req.__defineGetter__('protocol', function(){355 var proto = this.connection.encrypted356 ? 'https'357 : 'http';358 var trust = this.app.get('trust proxy fn');359360 if (!trust(this.connection.remoteAddress)) {356 return this.connection.encrypted357 ? 'https'358 : 'http';361 return proto;362 }363364 // Note: X-Forwarded-Proto is normally only ever a365 // single value, but this is to be safe.363 var proto = this.get('X-Forwarded-Proto') || 'http';366 proto = this.get('X-Forwarded-Proto') || proto;367 return proto.split(/\s*,\s*/)[0];368});369370/**
182 unmodified lines
modified:test/req.protocol.js+15 added
modified:History.md+1 added
13.x2===34 * Fix `req.protocol` for proxy-direct connections5 * Pass options from `res.sendfile` to `send`6 * deps: connect@2.24.07 - deps: body-parser@~1.5.08 - deps: compression@~1.0.9
1558 unmodified lines