mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Allow updating request's RequestURI and Host header via Request.URI()
This commit is contained in:
@@ -896,7 +896,7 @@ func (req *Request) onlyMultipartForm() bool {
|
||||
//
|
||||
// See also WriteTo.
|
||||
func (req *Request) Write(w *bufio.Writer) error {
|
||||
if len(req.Header.Host()) == 0 {
|
||||
if len(req.Header.Host()) == 0 || req.parsedURI {
|
||||
uri := req.URI()
|
||||
host := uri.Host()
|
||||
if len(host) == 0 {
|
||||
|
||||
@@ -11,6 +11,28 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRequestUpdateURI(t *testing.T) {
|
||||
var r Request
|
||||
r.Header.SetHost("aaa.bbb")
|
||||
r.SetRequestURI("/lkjkl/kjl")
|
||||
|
||||
// Modify request uri and host via URI() object and make sure
|
||||
// the requestURI and Host header are properly updated
|
||||
u := r.URI()
|
||||
u.SetPath("/123/432.html")
|
||||
u.SetHost("foobar.com")
|
||||
a := u.QueryArgs()
|
||||
a.Set("aaa", "bcse")
|
||||
|
||||
s := r.String()
|
||||
if !strings.HasPrefix(s, "GET /123/432.html?aaa=bcse") {
|
||||
t.Fatalf("cannot find %q in %q", "GET /123/432.html?aaa=bcse", s)
|
||||
}
|
||||
if strings.Index(s, "\r\nHost: foobar.com\r\n") < 0 {
|
||||
t.Fatalf("cannot find %q in %q", "\r\nHost: foobar.com\r\n", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestBodyStreamMultipleBodyCalls(t *testing.T) {
|
||||
var r Request
|
||||
|
||||
|
||||
Reference in New Issue
Block a user