From 93d982a5a4c2bfc75f8d31bee101f00a0c746518 Mon Sep 17 00:00:00 2001 From: Pieter Raubenheimer Date: Sun, 3 Apr 2016 20:14:10 +0100 Subject: [PATCH] Improve readability and fully comply with RFC7232 --- middleware/fileserver.go | 4 ++-- middleware/fileserver_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/middleware/fileserver.go b/middleware/fileserver.go index b86f5005..cba4da09 100644 --- a/middleware/fileserver.go +++ b/middleware/fileserver.go @@ -130,8 +130,8 @@ func (fh *fileHandler) serveFile(w http.ResponseWriter, r *http.Request, name st } // Add ETag header - e := fmt.Sprintf("\"%x-%x\"", d.ModTime().Unix(), d.Size()) - w.Header().Set("Etag", e) + e := fmt.Sprintf(`W/"%x-%x"`, d.ModTime().Unix(), d.Size()) + w.Header().Set("ETag", e) // Note: Errors generated by ServeContent are written immediately // to the response. This usually only happens if seeking fails (rare). diff --git a/middleware/fileserver_test.go b/middleware/fileserver_test.go index d42561b4..96292bdc 100644 --- a/middleware/fileserver_test.go +++ b/middleware/fileserver_test.go @@ -62,14 +62,14 @@ func TestServeHTTP(t *testing.T) { url: "https://foo/file1.html", expectedStatus: http.StatusOK, expectedBodyContent: testFiles["file1.html"], - expectedEtag: "\"1e240-13\"", + expectedEtag: `W/"1e240-13"`, }, // Test 3 - access folder with index file with trailing slash { url: "https://foo/dirwithindex/", expectedStatus: http.StatusOK, expectedBodyContent: testFiles[filepath.Join("dirwithindex", "index.html")], - expectedEtag: "\"1e240-20\"", + expectedEtag: `W/"1e240-20"`, }, // Test 4 - access folder with index file without trailing slash { @@ -109,7 +109,7 @@ func TestServeHTTP(t *testing.T) { url: "https://foo/dirwithindex/index.html", expectedStatus: http.StatusOK, expectedBodyContent: testFiles[filepath.Join("dirwithindex", "index.html")], - expectedEtag: "\"1e240-20\"", + expectedEtag: `W/"1e240-20"`, }, // Test 11 - send a request with query params {