Properly set "https" scheme in RequestCtx.URI() for TLS connections

This commit is contained in:
Aliaksandr Valialkin
2017-01-15 00:26:21 +02:00
parent 21021ceb31
commit b0de56d13b
4 changed files with 14 additions and 5 deletions
-3
View File
@@ -1008,9 +1008,6 @@ func testClientGet(t *testing.T, c clientGetter, addr string, n int) {
t.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusOK)
}
resultURI := string(body)
if strings.HasPrefix(uri, "https") {
resultURI = uri[:5] + resultURI[4:]
}
if resultURI != uri {
t.Fatalf("unexpected uri %q. Expecting %q", resultURI, uri)
}
+4 -1
View File
@@ -861,11 +861,14 @@ var errGetOnly = errors.New("non-GET request received")
//
// io.EOF is returned if r is closed before reading the first header byte.
func (req *Request) ReadLimitBody(r *bufio.Reader, maxBodySize int) error {
req.resetSkipHeader()
return req.readLimitBody(r, maxBodySize, false)
}
func (req *Request) readLimitBody(r *bufio.Reader, maxBodySize int, getOnly bool) error {
req.resetSkipHeader()
// Do not reset the request here - the caller must reset it before
// calling this method.
err := req.Header.Read(r)
if err != nil {
return err
+1 -1
View File
@@ -1479,8 +1479,8 @@ func (s *Server) serveConn(c net.Conn) error {
}
} else {
br, err = acquireByteReader(&ctx)
ctx.Request.isTLS = isTLS
}
ctx.Request.isTLS = isTLS
if err == nil {
if s.DisableHeaderNamesNormalizing {
+9
View File
@@ -633,6 +633,15 @@ func TestServerServeTLSEmbed(t *testing.T) {
ch := make(chan struct{})
go func() {
err := ServeTLSEmbed(ln, certData, keyData, func(ctx *RequestCtx) {
if !ctx.IsTLS() {
ctx.Error("expecting tls", StatusBadRequest)
return
}
scheme := ctx.URI().Scheme()
if string(scheme) != "https" {
ctx.Error(fmt.Sprintf("unexpected scheme=%q. Expecting %q", scheme, "https"), StatusBadRequest)
return
}
ctx.WriteString("success")
})
if err != nil {