Fix status code write

This commit is contained in:
DataHoarder 2022-06-06 22:39:49 +02:00
parent 7c38374d99
commit 6401a214ec
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
2 changed files with 12 additions and 3 deletions

View file

@ -154,10 +154,14 @@ func (c *FastHTTPContext) ServeStream(stream Stream) {
c.SetResponseCode(fasthttp.StatusPartialContent)
c.SetResponseHeader("Content-Range", fmt.Sprintf("bytes %d-%d/%d", rangeStart, rangeStart+rangeLength-1, size))
size = rangeLength
} else {
c.SetResponseCode(fasthttp.StatusOK)
}
c.ctx.SetBodyStream(stream, int(size))
} else {
c.SetResponseCode(fasthttp.StatusOK)
c.ctx.SetBodyStream(stream, -1)
}
}

View file

@ -152,17 +152,22 @@ func (c *NetHTTPContext) ServeStream(stream Stream) {
return
}
c.SetResponseCode(fasthttp.StatusPartialContent)
c.SetResponseHeader("Content-Length", strconv.FormatInt(size, 10))
c.SetResponseHeader("Content-Range", fmt.Sprintf("bytes %d-%d/%d", rangeStart, rangeStart+rangeLength-1, size))
c.SetResponseCode(fasthttp.StatusPartialContent)
size = rangeLength
} else {
c.SetResponseHeader("Content-Length", strconv.FormatInt(size, 10))
c.SetResponseCode(fasthttp.StatusOK)
}
c.SetResponseHeader("Content-Length", strconv.FormatInt(size, 10))
if !c.IsHead() {
io.CopyN(c.httpWriter, dstream, size)
}
} else {
c.SetResponseCode(fasthttp.StatusOK)
if !c.IsHead() {
c.SetResponseHeader("Transfer-Encoding", "chunked")
io.Copy(c.httpWriter, dstream)