mirror of https://github.com/go-gitea/gitea.git
Use standard HTTP library to serve files (#24693)
`http.ServeFile/ServeContent` handles `If-xxx`, `Content-Length`, `Range` and `Etag` correctly After this PR, storage files (eg: avatar) could be responded with correct Content-Length.pull/24694/head^2
parent
f745016092
commit
a94a8d0ab1
@ -1,35 +0,0 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package httplib
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type MockResponseWriter struct {
|
||||
header http.Header
|
||||
|
||||
StatusCode int
|
||||
BodyBuffer bytes.Buffer
|
||||
}
|
||||
|
||||
func (m *MockResponseWriter) Header() http.Header {
|
||||
return m.header
|
||||
}
|
||||
|
||||
func (m *MockResponseWriter) Write(bytes []byte) (int, error) {
|
||||
if m.StatusCode == 0 {
|
||||
m.StatusCode = http.StatusOK
|
||||
}
|
||||
return m.BodyBuffer.Write(bytes)
|
||||
}
|
||||
|
||||
func (m *MockResponseWriter) WriteHeader(statusCode int) {
|
||||
m.StatusCode = statusCode
|
||||
}
|
||||
|
||||
func NewMockResponseWriter() *MockResponseWriter {
|
||||
return &MockResponseWriter{header: http.Header{}}
|
||||
}
|
Loading…
Reference in New Issue