Skip to content

Commit 2968bb0

Browse files
committed
Fixed backport of req.protocol
1 parent ee0917f commit 2968bb0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

lib/request.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ req.__defineGetter__('isXMLHttpRequest', isxhr);
323323
req.__defineGetter__('xhr', isxhr);
324324

325325
/**
326-
* Return the protocol string "http" or "https",
327-
* when requested with TLS. When the "trust proxy"
326+
* Return the protocol string "http" or "https"
327+
* when requested with TLS. When the "trust proxy"
328328
* setting is enabled the "X-Forwarded-Proto" header
329329
* field will be trusted. If you're running behind
330330
* a reverse proxy that supplies https for you this
@@ -334,11 +334,24 @@ req.__defineGetter__('xhr', isxhr);
334334
* @api public
335335
*/
336336

337-
req.__defineGetter__('protocol', function(trustProxy){
338-
var trustProxy = this.app.settings['trust proxy'];
339-
return this.secure
337+
req.__defineGetter__('protocol', function(){
338+
var trustProxy = this.app.get('trust proxy');
339+
return this.connection.encrypted
340340
? 'https'
341341
: trustProxy
342-
? (this.header('X-Forwarded-Proto') || 'http')
342+
? (this.get('X-Forwarded-Proto') || 'http')
343343
: 'http';
344344
});
345+
346+
/**
347+
* Short-hand for:
348+
*
349+
* req.protocol == 'https'
350+
*
351+
* @return {Boolean}
352+
* @api public
353+
*/
354+
355+
req.__defineGetter__('secure', function(){
356+
return 'https' == this.protocol;
357+
});

0 commit comments

Comments
 (0)