Commit 93d982a5 authored by Pieter Raubenheimer's avatar Pieter Raubenheimer

Improve readability and fully comply with RFC7232

parent 572b9e4d
...@@ -130,8 +130,8 @@ func (fh *fileHandler) serveFile(w http.ResponseWriter, r *http.Request, name st ...@@ -130,8 +130,8 @@ func (fh *fileHandler) serveFile(w http.ResponseWriter, r *http.Request, name st
} }
// Add ETag header // Add ETag header
e := fmt.Sprintf("\"%x-%x\"", d.ModTime().Unix(), d.Size()) e := fmt.Sprintf(`W/"%x-%x"`, d.ModTime().Unix(), d.Size())
w.Header().Set("Etag", e) w.Header().Set("ETag", e)
// Note: Errors generated by ServeContent are written immediately // Note: Errors generated by ServeContent are written immediately
// to the response. This usually only happens if seeking fails (rare). // to the response. This usually only happens if seeking fails (rare).
......
...@@ -62,14 +62,14 @@ func TestServeHTTP(t *testing.T) { ...@@ -62,14 +62,14 @@ func TestServeHTTP(t *testing.T) {
url: "https://foo/file1.html", url: "https://foo/file1.html",
expectedStatus: http.StatusOK, expectedStatus: http.StatusOK,
expectedBodyContent: testFiles["file1.html"], expectedBodyContent: testFiles["file1.html"],
expectedEtag: "\"1e240-13\"", expectedEtag: `W/"1e240-13"`,
}, },
// Test 3 - access folder with index file with trailing slash // Test 3 - access folder with index file with trailing slash
{ {
url: "https://foo/dirwithindex/", url: "https://foo/dirwithindex/",
expectedStatus: http.StatusOK, expectedStatus: http.StatusOK,
expectedBodyContent: testFiles[filepath.Join("dirwithindex", "index.html")], expectedBodyContent: testFiles[filepath.Join("dirwithindex", "index.html")],
expectedEtag: "\"1e240-20\"", expectedEtag: `W/"1e240-20"`,
}, },
// Test 4 - access folder with index file without trailing slash // Test 4 - access folder with index file without trailing slash
{ {
...@@ -109,7 +109,7 @@ func TestServeHTTP(t *testing.T) { ...@@ -109,7 +109,7 @@ func TestServeHTTP(t *testing.T) {
url: "https://foo/dirwithindex/index.html", url: "https://foo/dirwithindex/index.html",
expectedStatus: http.StatusOK, expectedStatus: http.StatusOK,
expectedBodyContent: testFiles[filepath.Join("dirwithindex", "index.html")], expectedBodyContent: testFiles[filepath.Join("dirwithindex", "index.html")],
expectedEtag: "\"1e240-20\"", expectedEtag: `W/"1e240-20"`,
}, },
// Test 11 - send a request with query params // Test 11 - send a request with query params
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment