1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-01 22:09:21 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-06-09 08:41:50 -07:00
parent f4088cf594
commit aea64ed5e5
3 changed files with 15 additions and 8 deletions

View File

@ -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.

View File

@ -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"))

View File

@ -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())