mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Propagate 'https' scheme to request URI for TLS connections
This commit is contained in:
@@ -42,6 +42,8 @@ type Request struct {
|
||||
parsedPostArgs bool
|
||||
|
||||
keepBodyBuffer bool
|
||||
|
||||
isTLS bool
|
||||
}
|
||||
|
||||
// Response represents HTTP response.
|
||||
@@ -552,6 +554,7 @@ func (req *Request) copyToSkipBody(dst *Request) {
|
||||
|
||||
req.postArgs.CopyTo(&dst.postArgs)
|
||||
dst.parsedPostArgs = req.parsedPostArgs
|
||||
dst.isTLS = req.isTLS
|
||||
|
||||
// do not copy multipartForm - it will be automatically
|
||||
// re-created on the first call to MultipartForm.
|
||||
@@ -595,7 +598,7 @@ func (req *Request) parseURI() {
|
||||
}
|
||||
req.parsedURI = true
|
||||
|
||||
req.uri.parseQuick(req.Header.RequestURI(), &req.Header)
|
||||
req.uri.parseQuick(req.Header.RequestURI(), &req.Header, req.isTLS)
|
||||
}
|
||||
|
||||
// PostArgs returns POST arguments.
|
||||
@@ -744,6 +747,7 @@ func (req *Request) resetSkipHeader() {
|
||||
req.parsedURI = false
|
||||
req.postArgs.Reset()
|
||||
req.parsedPostArgs = false
|
||||
req.isTLS = false
|
||||
}
|
||||
|
||||
// RemoveMultipartFormFiles removes multipart/form-data temporary files
|
||||
|
||||
@@ -1377,6 +1377,28 @@ func TestReadBodyChunked(t *testing.T) {
|
||||
testReadBodyChunked(t, b, 12343)
|
||||
}
|
||||
|
||||
func TestRequestURITLS(t *testing.T) {
|
||||
uriNoScheme := "//foobar.com/baz/aa?bb=dd&dd#sdf"
|
||||
requestURI := "http:" + uriNoScheme
|
||||
requestURITLS := "https:" + uriNoScheme
|
||||
|
||||
var req Request
|
||||
|
||||
req.isTLS = true
|
||||
req.SetRequestURI(requestURI)
|
||||
uri := req.URI().String()
|
||||
if uri != requestURITLS {
|
||||
t.Fatalf("unexpected request uri: %q. Expecting %q", uri, requestURITLS)
|
||||
}
|
||||
|
||||
req.Reset()
|
||||
req.SetRequestURI(requestURI)
|
||||
uri = req.URI().String()
|
||||
if uri != requestURI {
|
||||
t.Fatalf("unexpected request uri: %q. Expecting %q", uri, requestURI)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestURI(t *testing.T) {
|
||||
host := "foobar.com"
|
||||
requestURI := "/aaa/bb+b%20d?ccc=ddd&qqq#1334dfds&=d"
|
||||
|
||||
@@ -1418,6 +1418,7 @@ func (s *Server) serveConn(c net.Conn) error {
|
||||
|
||||
ctx := s.acquireCtx(c)
|
||||
ctx.connTime = connTime
|
||||
isTLS := ctx.IsTLS()
|
||||
var (
|
||||
br *bufio.Reader
|
||||
bw *bufio.Writer
|
||||
@@ -1450,6 +1451,7 @@ func (s *Server) serveConn(c net.Conn) error {
|
||||
}
|
||||
} else {
|
||||
br, err = acquireByteReader(&ctx)
|
||||
ctx.Request.isTLS = isTLS
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
|
||||
@@ -217,8 +217,11 @@ func (u *URI) Parse(host, uri []byte) {
|
||||
u.parse(host, uri, nil)
|
||||
}
|
||||
|
||||
func (u *URI) parseQuick(uri []byte, h *RequestHeader) {
|
||||
func (u *URI) parseQuick(uri []byte, h *RequestHeader, isTLS bool) {
|
||||
u.parse(nil, uri, h)
|
||||
if isTLS {
|
||||
u.scheme = append(u.scheme[:0], strHTTPS...)
|
||||
}
|
||||
}
|
||||
|
||||
func (u *URI) parse(host, uri []byte, h *RequestHeader) {
|
||||
|
||||
Reference in New Issue
Block a user