Documentation
¶
Overview ¶
Package git provides functionality for interacting with Git repositories.
Index ¶
- Constants
- type Client
- func (c *Client) InfoRefs(ctx context.Context, service string) (*http.Response, error)
- func (c *Client) ReceivePack(ctx context.Context, body io.Reader) (*http.Response, error)
- func (c *Client) SSHReceivePack(ctx context.Context, body io.Reader) (*http.Response, error)
- func (c *Client) SSHUploadPack(ctx context.Context, body io.Reader) (*http.Response, error)
- func (c *Client) UploadPack(ctx context.Context, body io.Reader) (*http.Response, error)
- type ReplayBody
Constants ¶
const ( // DefaultReplayLimit is the most request-body bytes kept for replay. Git // negotiation for a pull and the commands plus pack of a small push fit // easily; larger bodies stream without replay, as before. DefaultReplayLimit = 1 << 20 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
URL string
Headers map[string]string
// PrepareRequest, if set, is called for every request after Headers and
// method-specific headers (such as Content-Type and Accept) are applied, so it
// can override them. Headers added later by the transport (User-Agent,
// X-Forwarded-For, correlation and tracing) are appended or replaced there, so
// they cannot be reliably set here. Implementations should only modify headers;
// replacing Body or URL is not supported.
PrepareRequest func(*http.Request) error
}
Client represents a client for interacting with Git repositories.
func (*Client) ReceivePack ¶
ReceivePack sends a Git push request to the server.
func (*Client) SSHReceivePack ¶ added in v14.36.0
SSHReceivePack sends a SSH Git push request to the server.
func (*Client) SSHUploadPack ¶ added in v14.36.0
SSHUploadPack sends a SSH Git fetch request to the server.
type ReplayBody ¶ added in v14.59.0
type ReplayBody struct {
// contains filtered or unexported fields
}
ReplayBody is a pipe whose read side can be re-opened from the start, so a streaming request body stays retryable.
Go's HTTP transport retries a request on a new connection when the pooled one dies before the request was processed (an idle close, an HTTP/2 GOAWAY, a REFUSED_STREAM), but only if it can replay the body: it needs Request. GetBody. An io.Pipe fed from SSH stdin cannot be replayed, so those retries failed with "net/http: cannot rewind body after connection loss". ReplayBody records what was consumed, up to a limit, and hands out fresh readers.
The write side is used by the goroutine forwarding SSH stdin. Each call to Reader or GetBody returns an independent reader that starts at the first byte; the transport closes the old one before replaying. Readers block for data, and the writer blocks when it is replayWindow ahead of the newest reader (or of the start, before any reader exists). Abort unblocks everyone once the request is over.
func NewReplayBody ¶ added in v14.59.0
func NewReplayBody(limit int) *ReplayBody
NewReplayBody returns a ReplayBody that keeps up to limit bytes for replay.
func (*ReplayBody) Abort ¶ added in v14.59.0
func (b *ReplayBody) Abort()
Abort tears the pipe down: pending and future Writes and Reads fail with io.ErrClosedPipe. Call it when the request is finished so the writer never blocks on a reader that will not come.
func (*ReplayBody) Close ¶ added in v14.59.0
func (b *ReplayBody) Close() error
Close ends the stream: readers see io.EOF once they consume everything.
func (*ReplayBody) CloseWithError ¶ added in v14.59.0
func (b *ReplayBody) CloseWithError(err error) error
CloseWithError ends the stream and makes readers return err instead of io.EOF once they consume everything.
func (*ReplayBody) GetBody ¶ added in v14.59.0
func (b *ReplayBody) GetBody() (io.ReadCloser, error)
GetBody is the http.Request.GetBody hook. It fails once more than the replay limit has been written, which makes the transport give up the retry exactly as it did before, instead of replaying a truncated body. The check and the new reader happen under one lock, so a concurrent Write cannot trim data the returned reader needs.
func (*ReplayBody) Reader ¶ added in v14.59.0
func (b *ReplayBody) Reader() io.ReadCloser
Reader returns a new reader positioned at the start of the stream. It becomes the reader that controls backpressure. Take the first reader before starting the writer, so backpressure applies from the first Write.