Skip to content

Commit d229aed

Browse files
authored
Convert int to string using fmt.Sprintf (#205)
1 parent fa1a373 commit d229aed

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

static.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package macaron
1717

1818
import (
1919
"encoding/base64"
20+
"fmt"
2021
"log"
2122
"net/http"
2223
"path"
@@ -183,7 +184,7 @@ func staticHandler(ctx *Context, log *log.Logger, opt StaticOptions) bool {
183184
}
184185

185186
if opt.ETag {
186-
tag := `"` + GenerateETag(string(fi.Size()), fi.Name(), fi.ModTime().UTC().Format(http.TimeFormat)) + `"`
187+
tag := `"` + GenerateETag(fmt.Sprintf("%d", fi.Size()), fi.Name(), fi.ModTime().UTC().Format(http.TimeFormat)) + `"`
187188
ctx.Resp.Header().Set("ETag", tag)
188189
if ctx.Req.Header.Get("If-None-Match") == tag {
189190
ctx.Resp.WriteHeader(http.StatusNotModified)

static_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package macaron
1717

1818
import (
1919
"bytes"
20+
"fmt"
2021
"io/ioutil"
2122
"net/http"
2223
"net/http/httptest"
@@ -197,7 +198,7 @@ func Test_Static_Options(t *testing.T) {
197198
req, err := http.NewRequest("GET", "http://localhost:4000/macaron.go", nil)
198199
So(err, ShouldBeNil)
199200
m.ServeHTTP(resp, req)
200-
tag := GenerateETag(string(resp.Body.Len()), "macaron.go", resp.Header().Get("last-modified"))
201+
tag := GenerateETag(fmt.Sprintf("%d", resp.Body.Len()), "macaron.go", resp.Header().Get("last-modified"))
201202

202203
So(resp.Header().Get("ETag"), ShouldEqual, `"`+tag+`"`)
203204
})
@@ -211,7 +212,7 @@ func Test_Static_Options(t *testing.T) {
211212
req, err := http.NewRequest("GET", "http://localhost:4000/macaron.go", nil)
212213
So(err, ShouldBeNil)
213214
m.ServeHTTP(resp, req)
214-
tag := GenerateETag(string(resp.Body.Len()), "macaron.go", resp.Header().Get("last-modified"))
215+
tag := GenerateETag(fmt.Sprintf("%d", resp.Body.Len()), "macaron.go", resp.Header().Get("last-modified"))
215216

216217
// Second request with ETag in If-None-Match
217218
resp = httptest.NewRecorder()

0 commit comments

Comments
 (0)