aboutsummaryrefslogtreecommitdiff
path: root/client_test.go
diff options
context:
space:
mode:
authorGravatar Erik Dubbelboer <erik@dubbelboer.com> 2020-04-25 20:54:59 +0200
committerGravatar GitHub <noreply@github.com> 2020-04-25 20:54:59 +0200
commit079f39bddceb89b52f80952dd9beed0a8fc331d2 (patch)
treee16c30b14b4e16a397685a6eada20926fde3bf2b /client_test.go
parentFix integer overflow handling in parseUintBuf() (#789) (diff)
downloadfasthttp-079f39bddceb89b52f80952dd9beed0a8fc331d2.tar.gz
fasthttp-079f39bddceb89b52f80952dd9beed0a8fc331d2.tar.bz2
fasthttp-079f39bddceb89b52f80952dd9beed0a8fc331d2.zip
Don't allow ASCII control character in URLs (#790)
* Don't allow ASCII control character in URLs * Add tests
Diffstat (limited to 'client_test.go')
-rw-r--r--client_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/client_test.go b/client_test.go
index 59bc413..3f9bc77 100644
--- a/client_test.go
+++ b/client_test.go
@@ -20,6 +20,38 @@ import (
"github.com/valyala/fasthttp/fasthttputil"
)
+func TestClientInvalidURI(t *testing.T) {
+ t.Parallel()
+
+ ln := fasthttputil.NewInmemoryListener()
+ requests := int64(0)
+ s := &Server{
+ Handler: func(ctx *RequestCtx) {
+ atomic.AddInt64(&requests, 1)
+ },
+ }
+ go s.Serve(ln)
+ c := &Client{
+ Dial: func(addr string) (net.Conn, error) {
+ return ln.Dial()
+ },
+ }
+ req, res := AcquireRequest(), AcquireResponse()
+ defer func() {
+ ReleaseRequest(req)
+ ReleaseResponse(res)
+ }()
+ req.Header.SetMethod(MethodGet)
+ req.SetRequestURI("http://example.com\r\n\r\nGET /\r\n\r\n")
+ err := c.Do(req, res)
+ if err == nil {
+ t.Fatal("expected error (missing required Host header in request)")
+ }
+ if n := atomic.LoadInt64(&requests); n != 0 {
+ t.Fatalf("0 requests expected, got %d", n)
+ }
+}
+
func TestClientGetWithBody(t *testing.T) {
t.Parallel()