diff options
author | 6543 <6543@obermui.de> | 2023-07-07 07:31:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-07 05:31:56 +0000 |
commit | 8995046110147ae2c8c98be4e0a8c0b643ccc29c (patch) | |
tree | 94a3007199687c0a68eee5889af1619f1eebaf61 /modules/httplib | |
parent | b1eb1676aa95d776ff9085002641ad62e040cd93 (diff) | |
download | gitea-8995046110147ae2c8c98be4e0a8c0b643ccc29c.tar.gz gitea-8995046110147ae2c8c98be4e0a8c0b643ccc29c.zip |
Less naked returns (#25713)
just a step towards #25655
and some related refactoring
Diffstat (limited to 'modules/httplib')
-rw-r--r-- | modules/httplib/serve.go | 7 | ||||
-rw-r--r-- | modules/httplib/serve_test.go | 3 |
2 files changed, 6 insertions, 4 deletions
diff --git a/modules/httplib/serve.go b/modules/httplib/serve.go index 12d68c2d65..a193ed901c 100644 --- a/modules/httplib/serve.go +++ b/modules/httplib/serve.go @@ -206,7 +206,7 @@ func ServeContentByReader(r *http.Request, w http.ResponseWriter, filePath strin _, _ = io.CopyN(w, reader, partialLength) // just like http.ServeContent, not necessary to handle the error } -func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath string, modTime time.Time, reader io.ReadSeeker) { +func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath string, modTime *time.Time, reader io.ReadSeeker) { buf := make([]byte, mimeDetectionBufferLen) n, err := util.ReadAtMost(reader, buf) if err != nil { @@ -221,5 +221,8 @@ func ServeContentByReadSeeker(r *http.Request, w http.ResponseWriter, filePath s buf = buf[:n] } setServeHeadersByFile(r, w, filePath, buf) - http.ServeContent(w, r, path.Base(filePath), modTime, reader) + if modTime == nil { + modTime = &time.Time{} + } + http.ServeContent(w, r, path.Base(filePath), *modTime, reader) } diff --git a/modules/httplib/serve_test.go b/modules/httplib/serve_test.go index fed4611d21..c2229dffe9 100644 --- a/modules/httplib/serve_test.go +++ b/modules/httplib/serve_test.go @@ -11,7 +11,6 @@ import ( "os" "strings" "testing" - "time" "github.com/stretchr/testify/assert" ) @@ -78,7 +77,7 @@ func TestServeContentByReadSeeker(t *testing.T) { defer seekReader.Close() w := httptest.NewRecorder() - ServeContentByReadSeeker(r, w, "test", time.Time{}, seekReader) + ServeContentByReadSeeker(r, w, "test", nil, seekReader) assert.Equal(t, expectedStatusCode, w.Code) if expectedStatusCode == http.StatusPartialContent || expectedStatusCode == http.StatusOK { assert.Equal(t, fmt.Sprint(len(expectedContent)), w.Header().Get("Content-Length")) |