Skip to content

Commit

Permalink
update header.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyenought committed Nov 15, 2023
1 parent 4b6d14b commit afeb535
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions pkg/protocol/http1/resp/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func (c *chunkedBodyWriter) Flush() error {
// Warning: do not call this method by yourself, unless you know what you are doing.
func (c *chunkedBodyWriter) Finalize() error {
c.Do(func() {
// in case no actual data from user
if !c.wroteHeader {
c.r.Header.SetContentLength(-1)
if c.finalizeErr = WriteHeader(&c.r.Header, c.w); c.finalizeErr != nil {
return
}
c.wroteHeader = true
}
c.finalizeErr = ext.WriteChunk(c.w, nil, true)
if c.finalizeErr != nil {
return
Expand All @@ -70,7 +78,8 @@ func (c *chunkedBodyWriter) Finalize() error {

func NewChunkedBodyWriter(r *protocol.Response, w network.Writer) network.ExtWriter {
return &chunkedBodyWriter{
r: r,
w: w,
r: r,
w: w,
Once: sync.Once{},
}
}

0 comments on commit afeb535

Please sign in to comment.