mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 13:56:57 +00:00
code review fixes woohoo
This commit is contained in:
parent
6f7e694fd4
commit
924ad83ac6
2 changed files with 14 additions and 15 deletions
|
@ -187,12 +187,13 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
|
||||||
|
|
||||||
// Check if size of gzipped response is greater than fileCacheSizeLimit and return gzipped
|
// Check if size of gzipped response is greater than fileCacheSizeLimit and return gzipped
|
||||||
// response but uncached or return non-gzip response if not supported
|
// response but uncached or return non-gzip response if not supported
|
||||||
len := int64(buf.Len());
|
shouldRespBeSavedToCache := int64(buf.Len()) < fileCacheSizeLimit
|
||||||
shouldRespBeSavedToCache := len < fileCacheSizeLimit
|
|
||||||
if !shouldRespBeSavedToCache {
|
if !shouldRespBeSavedToCache {
|
||||||
return io.NopCloser(buf), resp.Response.Header, resp.StatusCode, err
|
if acceptsGzip {
|
||||||
} else if !shouldRespBeSavedToCache && !acceptsGzip {
|
return io.NopCloser(buf), resp.Response.Header, resp.StatusCode, err
|
||||||
return reader, resp.Response.Header, resp.StatusCode, err
|
} else {
|
||||||
|
return reader, resp.Response.Header, resp.StatusCode, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now we write to cache and respond at the same time
|
// now we write to cache and respond at the same time
|
||||||
|
|
|
@ -202,16 +202,14 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client, redi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decompress response if gzip is not supported
|
// Decompress response if gzip is not supported
|
||||||
r := reader
|
if acceptsGzip {
|
||||||
if !acceptsGzip {
|
|
||||||
r, err = gzip.NewReader(reader)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Msgf("Couldn't decompress for %q", o.TargetPath)
|
|
||||||
html.ReturnErrorPage(ctx, "", http.StatusInternalServerError)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ctx.RespWriter.Header().Set("Content-Encoding", "gzip")
|
ctx.RespWriter.Header().Set("Content-Encoding", "gzip")
|
||||||
|
} else if r, err := gzip.NewReader(reader); err == nil {
|
||||||
|
reader = r
|
||||||
|
} else {
|
||||||
|
log.Error().Err(err).Msgf("Couldn't decompress for %q", o.TargetPath)
|
||||||
|
html.ReturnErrorPage(ctx, "", http.StatusInternalServerError)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ETag & MIME
|
// Set ETag & MIME
|
||||||
|
@ -223,7 +221,7 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client, redi
|
||||||
|
|
||||||
// Write the response body to the original request
|
// Write the response body to the original request
|
||||||
if reader != nil {
|
if reader != nil {
|
||||||
_, err := io.Copy(ctx.RespWriter, r)
|
_, err := io.Copy(ctx.RespWriter, reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("Couldn't write body for %q", o.TargetPath)
|
log.Error().Err(err).Msgf("Couldn't write body for %q", o.TargetPath)
|
||||||
html.ReturnErrorPage(ctx, "", http.StatusInternalServerError)
|
html.ReturnErrorPage(ctx, "", http.StatusInternalServerError)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue