Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 15:49:16 -05:00
pkg-proxy/internal/handler/upstream_body.go
Simon Chrzanowski 6dbda21faf Move the in-memory truncation fix to its own pull request
The change to ReadMetadataSized and fetchUpstreamMetadata, with its tests,
is now #649. upstreamBodyReader stays for storeUpstreamMetadata, in a file
of its own that #649 adds with the same content.
2026-11-01 12:49:09 +01:00

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 }