mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-05-12 04:57:50 +00:00
Implement static serving of compressed files
This commit is contained in:
parent
e5320e1972
commit
1c0ce28d8e
4 changed files with 154 additions and 20 deletions
|
@ -37,15 +37,20 @@ type FileResponse struct {
|
|||
Exists bool
|
||||
IsSymlink bool
|
||||
ETag string
|
||||
MimeType string
|
||||
Body []byte
|
||||
|
||||
// uncompressed MIME type
|
||||
MimeType string
|
||||
|
||||
// raw MIME type (if compressed, type of compression)
|
||||
RawMime string
|
||||
Body []byte
|
||||
}
|
||||
|
||||
func (f FileResponse) IsEmpty() bool {
|
||||
return len(f.Body) == 0
|
||||
}
|
||||
|
||||
func (f FileResponse) createHttpResponse(cacheKey string) (header http.Header, statusCode int) {
|
||||
func (f FileResponse) createHttpResponse(cacheKey string, decompress bool) (header http.Header, statusCode int) {
|
||||
header = make(http.Header)
|
||||
|
||||
if f.Exists {
|
||||
|
@ -58,7 +63,12 @@ func (f FileResponse) createHttpResponse(cacheKey string) (header http.Header, s
|
|||
header.Set(giteaObjectTypeHeader, objTypeSymlink)
|
||||
}
|
||||
header.Set(ETagHeader, f.ETag)
|
||||
header.Set(ContentTypeHeader, f.MimeType)
|
||||
|
||||
if decompress {
|
||||
header.Set(ContentTypeHeader, f.MimeType)
|
||||
} else {
|
||||
header.Set(ContentTypeHeader, f.RawMime)
|
||||
}
|
||||
header.Set(ContentLengthHeader, fmt.Sprintf("%d", len(f.Body)))
|
||||
header.Set(PagesCacheIndicatorHeader, "true")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue