From aea64ed5e5fe18d77011aa2a58769121788417f7 Mon Sep 17 00:00:00 2001 From: Vishal Rana Date: Thu, 9 Jun 2016 08:41:50 -0700 Subject: [PATCH] Fixed #556 Signed-off-by: Vishal Rana --- engine/standard/request.go | 7 ++++++- engine/standard/request_test.go | 9 +++++---- engine/test/test_request.go | 7 ++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/engine/standard/request.go b/engine/standard/request.go index 0b3bde6e..99f63ece 100644 --- a/engine/standard/request.go +++ b/engine/standard/request.go @@ -43,7 +43,12 @@ func (r *Request) IsTLS() bool { // Scheme implements `engine.Request#Scheme` function. func (r *Request) Scheme() string { - return r.Request.URL.Scheme + // Can't use `r.Request.URL.Scheme` + // See: https://groups.google.com/forum/#!topic/golang-nuts/pMUkBlQBDF0 + if r.IsTLS() { + return "https" + } + return "http" } // Host implements `engine.Request#Host` function. diff --git a/engine/standard/request_test.go b/engine/standard/request_test.go index 3a9fcc2a..a88b57e1 100644 --- a/engine/standard/request_test.go +++ b/engine/standard/request_test.go @@ -2,18 +2,19 @@ package standard import ( "bufio" - "github.com/labstack/echo/engine/test" - "github.com/labstack/gommon/log" - "github.com/stretchr/testify/assert" "net/http" "net/url" "strings" "testing" + + "github.com/labstack/echo/engine/test" + "github.com/labstack/gommon/log" + "github.com/stretchr/testify/assert" ) func TestRequest(t *testing.T) { httpReq, _ := http.ReadRequest(bufio.NewReader(strings.NewReader(test.MultipartRequest))) - url, _ := url.Parse("https://github.com/labstack/echo") + url, _ := url.Parse("http://github.com/labstack/echo") httpReq.URL = url httpReq.RemoteAddr = "127.0.0.1" req := NewRequest(httpReq, log.New("echo")) diff --git a/engine/test/test_request.go b/engine/test/test_request.go index 83149ddf..b6ec4e8d 100644 --- a/engine/test/test_request.go +++ b/engine/test/test_request.go @@ -1,11 +1,12 @@ package test import ( - "github.com/labstack/echo/engine" - "github.com/stretchr/testify/assert" "io/ioutil" "strings" "testing" + + "github.com/labstack/echo/engine" + "github.com/stretchr/testify/assert" ) const MultipartRequest = `POST /labstack/echo HTTP/1.1 @@ -47,7 +48,7 @@ func RequestTest(t *testing.T, request engine.Request) { assert.Equal(t, "/labstack/echo", request.URL().Path()) assert.Equal(t, "https://github.com/", request.Referer()) assert.Equal(t, "127.0.0.1", request.Header().Get("X-Real-IP")) - assert.Equal(t, "https", request.Scheme()) + assert.Equal(t, "http", request.Scheme()) assert.Equal(t, "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; de-de) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10", request.UserAgent()) assert.Equal(t, "127.0.0.1", request.RemoteAddress()) assert.Equal(t, "POST", request.Method())