From 77a4cfb8297bed0bc577425a6f42a0397547ca32 Mon Sep 17 00:00:00 2001 From: initial-wu Date: Thu, 7 Jun 2018 22:50:26 +0800 Subject: [PATCH] Simplify processes in the getter `request.protocol` (#1203) --- lib/request.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/request.js b/lib/request.js index 16be9a2..7881d4c 100644 --- a/lib/request.js +++ b/lib/request.js @@ -397,11 +397,10 @@ module.exports = { */ get protocol() { - const proxy = this.app.proxy; if (this.socket.encrypted) return 'https'; - if (!proxy) return 'http'; - const proto = this.get('X-Forwarded-Proto') || 'http'; - return proto.split(/\s*,\s*/)[0]; + if (!this.app.proxy) return 'http'; + const proto = this.get('X-Forwarded-Proto'); + return proto ? proto.split(/\s*,\s*/)[0] : 'http'; }, /**