diff --git a/httpx/header_request.go b/httpx/header_request.go index efd2183..3db5ed2 100644 --- a/httpx/header_request.go +++ b/httpx/header_request.go @@ -28,6 +28,10 @@ func (h *RequestHeader) SetMethod(method string) { h.hdr.SetMethod(method) } +func (h *RequestHeader) SetHost(host string) { + h.hdr.SetHost(host) +} + func (h *RequestHeader) RequestURI() []byte { return h.hdr.RequestURI() } func (h *RequestHeader) SetRequestURI(uri string) { diff --git a/httpx/header_test.go b/httpx/header_test.go index 00f2997..901fa29 100644 --- a/httpx/header_test.go +++ b/httpx/header_test.go @@ -181,7 +181,21 @@ func TestRequestDisableSpecialHeaders(t *testing.T) { func TestRequest(t *testing.T) { var req RequestHeader req.SetRequestURI("http://example.com") - - var b bytes.Buffer - b.Write(req.Header()) + req.SetHost("example.com") + req.SetMethod("PUT") + req.SetUserAgent("test") + req.SetContentType("text/plain") + // req.SetProtocol("HTTP/2.1") + result := string(req.Header()) + b := bufio.NewReader(strings.NewReader(result)) + + var loop RequestHeader + err := loop.Read(b) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + resultLoopback := string(loop.Header()) + if result != resultLoopback { + t.Errorf("loopback mismatch: %q got %q", result, resultLoopback) + } }