mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 15:49:16 -05:00
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.
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 }
|