Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fixes short write error. #107

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/nightly-caddy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:

jobs:
nightly-caddy:
name: "Nightly Caddy (caddy version: ${{ github.event.inputs.caddyversion || 'master' }})"
strategy:
matrix:
go-version: [1.20.x]
Expand Down
13 changes: 11 additions & 2 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (i *rwInterceptor) WriteHeader(statusCode int) {
i.statusCode = statusCode

if it := i.tx.ProcessResponseHeaders(statusCode, i.proto); it != nil {
i.w.Header().Del("Content-Length")
i.statusCode = obtainStatusCodeFromInterruptionOrDefault(it, i.statusCode)
i.flushWriteHeader()
return
Expand Down Expand Up @@ -73,7 +74,11 @@ func (i *rwInterceptor) Write(b []byte) (int, error) {
// if there is an interruption it must be from at least phase 4 and hence
// WriteHeader or Write should have been called and hence the status code
// has been flushed to the delegated response writer.
return 0, nil
//
// We return the number of bytes as according to the interface io.Writer
// if we don't return an error, the number of bytes written is len(p).
// See https://pkg.go.dev/io#Writer
return len(b), nil
}

if !i.wroteHeader {
Expand All @@ -89,7 +94,11 @@ func (i *rwInterceptor) Write(b []byte) (int, error) {
i.overrideWriteHeader(it.Status)
// We only flush the status code after an interruption.
i.flushWriteHeader()
return 0, nil

// We return the number of bytes as according to the interface io.Writer
// if we don't return an error, the number of bytes written is len(p).
// See https://pkg.go.dev/io#Writer
return len(b), nil
}
return n, err
}
Expand Down
Loading