aboutsummaryrefslogtreecommitdiff
path: root/header_regression_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-12-02 20:17:50 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2015-12-02 20:17:50 +0200
commitfe212fe380a7ed880fa463beb7e6dbaea2e69d26 (patch)
tree0ea4357606ce16209fb90924177f204b499aaa1e /header_regression_test.go
parentAdded client benchmarks into readme (diff)
downloadfasthttp-fe212fe380a7ed880fa463beb7e6dbaea2e69d26.tar.gz
fasthttp-fe212fe380a7ed880fa463beb7e6dbaea2e69d26.tar.bz2
fasthttp-fe212fe380a7ed880fa463beb7e6dbaea2e69d26.zip
Issue #6: Add support for PATCH method and other methods which may contain body
Diffstat (limited to 'header_regression_test.go')
-rw-r--r--header_regression_test.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/header_regression_test.go b/header_regression_test.go
index e7530d9..f3c425f 100644
--- a/header_regression_test.go
+++ b/header_regression_test.go
@@ -6,16 +6,25 @@ import (
"testing"
)
-func TestRequestHeaderSetContentType_Issue6(t *testing.T) {
+func TestIssue6RequestHeaderSetContentType(t *testing.T) {
+ testIssue6RequestHeaderSetContentType(t, "GET")
+ testIssue6RequestHeaderSetContentType(t, "POST")
+ testIssue6RequestHeaderSetContentType(t, "PUT")
+ testIssue6RequestHeaderSetContentType(t, "PATCH")
+}
+
+func testIssue6RequestHeaderSetContentType(t *testing.T, method string) {
contentType := "application/json"
+ contentLength := 123
var h RequestHeader
+ h.SetMethod(method)
h.SetRequestURI("http://localhost/test")
h.SetContentType(contentType)
+ h.SetContentLength(contentLength)
+
+ issue6VerifyRequestHeader(t, &h, contentType, contentLength, method)
- if string(h.ContentType()) != contentType {
- t.Fatalf("unexpected content-type: %q. Expecting %q", h.ContentType(), contentType)
- }
s := h.String()
var h1 RequestHeader
@@ -24,7 +33,21 @@ func TestRequestHeaderSetContentType_Issue6(t *testing.T) {
if err := h1.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
}
- if string(h1.ContentType()) != contentType {
- t.Fatalf("unexpected content-type: %q. Expecting %q", h1.ContentType(), contentType)
+ issue6VerifyRequestHeader(t, &h1, contentType, contentLength, method)
+}
+
+func issue6VerifyRequestHeader(t *testing.T, h *RequestHeader, contentType string, contentLength int, method string) {
+ if string(h.ContentType()) != contentType {
+ t.Fatalf("unexpected content-type: %q. Expecting %q. method=%q", h.ContentType(), contentType, method)
+ }
+ if string(h.Method()) != method {
+ t.Fatalf("unexpected method: %q. Expecting %q", h.Method(), method)
+ }
+ if method != "GET" {
+ if h.ContentLength() != contentLength {
+ t.Fatalf("unexpected content-length: %d. Expecting %d. method=%q", h.ContentLength(), contentLength, method)
+ }
+ } else if h.ContentLength() != 0 {
+ t.Fatalf("unexpected content-length for GET method: %d. Expecting 0", h.ContentLength())
}
}