mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-12-02 18:45:29 +00:00
Tell fasthttp to not set "Content-Length: 0" on non cached content (#107)
fix #97 Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/107
This commit is contained in:
parent
baf4e7e326
commit
5411c96ef3
@ -59,6 +59,8 @@ func TestGetContent(t *testing.T) {
|
|||||||
assert.EqualValues(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
|
assert.EqualValues(t, "text/html; charset=utf-8", resp.Header.Get("Content-Type"))
|
||||||
assert.True(t, getSize(resp.Body) > 100)
|
assert.True(t, getSize(resp.Body) > 100)
|
||||||
assert.Len(t, resp.Header.Get("ETag"), 42)
|
assert.Len(t, resp.Header.Get("ETag"), 42)
|
||||||
|
|
||||||
|
// TODO: test get of non cachable content (content size > fileCacheSizeLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCustomDomain(t *testing.T) {
|
func TestCustomDomain(t *testing.T) {
|
||||||
|
@ -82,7 +82,6 @@ func (client *Client) ServeRawContent(uri string) (*fasthttp.Response, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// resp.SetBodyStream(&strings.Reader{}, -1)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -181,6 +181,9 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client,
|
|||||||
var cacheBodyWriter bytes.Buffer
|
var cacheBodyWriter bytes.Buffer
|
||||||
if res != nil {
|
if res != nil {
|
||||||
if res.Header.ContentLength() > fileCacheSizeLimit {
|
if res.Header.ContentLength() > fileCacheSizeLimit {
|
||||||
|
// fasthttp else will set "Content-Length: 0"
|
||||||
|
ctx.Response.SetBodyStream(&strings.Reader{}, -1)
|
||||||
|
|
||||||
err = res.BodyWriteTo(ctx.Response.BodyWriter())
|
err = res.BodyWriteTo(ctx.Response.BodyWriter())
|
||||||
} else {
|
} else {
|
||||||
// TODO: cache is half-empty if request is cancelled - does the ctx.Err() below do the trick?
|
// TODO: cache is half-empty if request is cancelled - does the ctx.Err() below do the trick?
|
||||||
|
Loading…
Reference in New Issue
Block a user