Skip to content

Commit 8e628a0

Browse files
authored
chore: fixes short write error. (#107)
* chore: fixes short write error. * fix: removes the content length header on phase 3 interruption so caddy does not fail as per caddyserver/caddy#5952.
1 parent e6cbb66 commit 8e628a0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.github/workflows/nightly-caddy.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313

1414
jobs:
1515
nightly-caddy:
16+
name: "Nightly Caddy (caddy version: ${{ github.event.inputs.caddyversion || 'master' }})"
1617
strategy:
1718
matrix:
1819
go-version: [1.20.x]

interceptor.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func (i *rwInterceptor) WriteHeader(statusCode int) {
4242
i.statusCode = statusCode
4343

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

7984
if !i.wroteHeader {
@@ -89,7 +94,11 @@ func (i *rwInterceptor) Write(b []byte) (int, error) {
8994
i.overrideWriteHeader(it.Status)
9095
// We only flush the status code after an interruption.
9196
i.flushWriteHeader()
92-
return 0, nil
97+
98+
// We return the number of bytes as according to the interface io.Writer
99+
// if we don't return an error, the number of bytes written is len(p).
100+
// See https://pkg.go.dev/io#Writer
101+
return len(b), nil
93102
}
94103
return n, err
95104
}

0 commit comments

Comments
 (0)