aboutsummaryrefslogtreecommitdiff
path: root/fs_test.go
diff options
context:
space:
mode:
authorGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-01-18 20:40:43 +0200
committerGravatar Aliaksandr Valialkin <valyala@gmail.com> 2016-01-18 20:40:43 +0200
commita208149ac4a65af868086d6fe31b5943e9f36733 (patch)
tree6022b97177a0c837a7e444b0c56189f660465b2c /fs_test.go
parentFixed a typo (diff)
downloadfasthttp-a208149ac4a65af868086d6fe31b5943e9f36733.tar.gz
fasthttp-a208149ac4a65af868086d6fe31b5943e9f36733.tar.bz2
fasthttp-a208149ac4a65af868086d6fe31b5943e9f36733.zip
FS optimization: do not read file contents on HEAD requests
Diffstat (limited to 'fs_test.go')
-rw-r--r--fs_test.go41
1 files changed, 39 insertions, 2 deletions
diff --git a/fs_test.go b/fs_test.go
index 5d79487..d138c60 100644
--- a/fs_test.go
+++ b/fs_test.go
@@ -12,7 +12,44 @@ import (
"time"
)
-func TestFSServeFileCompressed(t *testing.T) {
+func TestServeFileHead(t *testing.T) {
+ var ctx RequestCtx
+ var req Request
+ req.Header.SetMethod("HEAD")
+ req.SetRequestURI("http://foobar.com/baz")
+ ctx.Init(&req, nil, nil)
+
+ ServeFile(&ctx, "fs.go")
+
+ var resp Response
+ resp.SkipBody = true
+ s := ctx.Response.String()
+ br := bufio.NewReader(bytes.NewBufferString(s))
+ if err := resp.Read(br); err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
+
+ ce := resp.Header.Peek("Content-Encoding")
+ if len(ce) > 0 {
+ t.Fatalf("Unexpected 'Content-Encoding' %q", ce)
+ }
+
+ body := resp.Body()
+ if len(body) > 0 {
+ t.Fatalf("unexpected response body %q. Expecting empty body", body)
+ }
+
+ expectedBody, err := getFileContents("/fs.go")
+ if err != nil {
+ t.Fatalf("unexpected error: %s", err)
+ }
+ contentLength := resp.Header.ContentLength()
+ if contentLength != len(expectedBody) {
+ t.Fatalf("unexpected Content-Length: %d. expecting %d", contentLength, len(expectedBody))
+ }
+}
+
+func TestServeFileCompressed(t *testing.T) {
var ctx RequestCtx
var req Request
req.SetRequestURI("http://foobar.com/baz")
@@ -46,7 +83,7 @@ func TestFSServeFileCompressed(t *testing.T) {
}
}
-func TestFSServeFileUncompressed(t *testing.T) {
+func TestServeFileUncompressed(t *testing.T) {
var ctx RequestCtx
var req Request
req.SetRequestURI("http://foobar.com/baz")