mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-10 08:09:17 -05:00
ReadMetadataSized took the transport's io.ErrUnexpectedEOF for the end of a body shorter than its size hint. A document upstream closed before its Content-Length was served with a 200 and cached, or failed the cooldown filter with a 502, instead of the cached copy being served. Upstream bodies are now read through a reader that marks their read errors, and such a body fails the read as an upstream failure.
26 lines
791 B
Go
26 lines
791 B
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
)
|
|
|
|
// upstreamBodyReader marks a failure to read a document from upstream, so a
|
|
// body upstream cuts off is told apart from one that ends, and from a
|
|
// failure to store it.
|
|
type upstreamBodyReader struct{ r io.Reader }
|
|
|
|
func (u upstreamBodyReader) Read(b []byte) (int, error) {
|
|
n, err := u.r.Read(b)
|
|
if err != nil && !errors.Is(err, io.EOF) {
|
|
err = &upstreamBodyError{err}
|
|
}
|
|
return n, err
|
|
}
|
|
|
|
// upstreamBodyError is a failure to read a document from upstream. It is
|
|
// handled as an upstream failure: the stored copy, if any, is served.
|
|
type upstreamBodyError struct{ err error }
|
|
|
|
func (e *upstreamBodyError) Error() string { return "reading upstream metadata: " + e.err.Error() }
|
|
func (e *upstreamBodyError) Unwrap() error { return e.err }
|