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 0356859 · 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
242 unmodified lines
243/**244 * Return the protocol string "http" or "https"245 * when requested with TLS. When the "trust proxy"246 * setting trusts the socket address, the247 * "X-Forwarded-Proto" header field will be trusted.247 * "X-Forwarded-Proto" header field will be trusted248 * and used if present.249 *250 * If you're running behind a reverse proxy that251 * supplies https for you this may be enabled.252 *253 * @return {String}254 * @api public255 */256257defineGetter(req, 'protocol', function protocol(){258 var proto = this.connection.encrypted259 ? 'https'260 : 'http';261 var trust = this.app.get('trust proxy fn');262263 if (!trust(this.connection.remoteAddress)) {259 return this.connection.encrypted260 ? 'https'261 : 'http';264 return proto;265 }266267 // Note: X-Forwarded-Proto is normally only ever a268 // single value, but this is to be safe.266 var proto = this.get('X-Forwarded-Proto') || 'http';269 proto = this.get('X-Forwarded-Proto') || proto;270 return proto.split(/\s*,\s*/)[0];271});272273/**
181 unmodified lines
modified:test/req.protocol.js+15 added
modified:History.md+1 added
1unreleased2==========34 * fix `req.protocol` for proxy-direct connections5 * configurable query parser with `app.set('query parser', parser)`6 - `app.set('query parser', 'extended')` parse with "qs" module7 - `app.set('query parser', 'simple')` parse with "querystring" core module8 - `app.set('query parser', false)` disable query string parsing
1835 unmodified lines