duplex

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplexHTTPCall

type DuplexHTTPCall struct {
	OnRequestSend func(*http.Request)
	// contains filtered or unexported fields
}

DuplexHTTPCall is a full-duplex stream between the client and server. The request body is the stream from client to server, and the response body is the reverse.

Be warned: we need to use some lesser-known APIs to do this with net/http.

func NewDuplexHTTPCall

func NewDuplexHTTPCall(ctx context.Context, httpClient HTTPClient, url *url.URL, sendUnary bool, header http.Header) *DuplexHTTPCall

func (*DuplexHTTPCall) BlockUntilResponseReady

func (d *DuplexHTTPCall) BlockUntilResponseReady() error

BlockUntilResponseReady returns when the response is ready or reports an error from initializing the request.

func (*DuplexHTTPCall) CloseRead

func (d *DuplexHTTPCall) CloseRead() error

CloseRead closes the response body.

func (*DuplexHTTPCall) CloseWrite

func (d *DuplexHTTPCall) CloseWrite() error

CloseWrite closes the request body. Callers *must* call CloseWrite before Read when using HTTP/1.x.

func (*DuplexHTTPCall) Header

func (d *DuplexHTTPCall) Header() http.Header

Header returns the HTTP request headers.

func (*DuplexHTTPCall) Method

func (d *DuplexHTTPCall) Method() string

Method returns the HTTP method for the request (GET or POST).

func (*DuplexHTTPCall) Read

func (d *DuplexHTTPCall) Read(data []byte) (int, error)

Read from the response body. Returns the first error passed to SetError.

func (*DuplexHTTPCall) ResponseHeader

func (d *DuplexHTTPCall) ResponseHeader() http.Header

ResponseHeader returns the response HTTP headers.

func (*DuplexHTTPCall) ResponseStatusCode

func (d *DuplexHTTPCall) ResponseStatusCode() (int, error)

ResponseStatusCode is the response's HTTP status code.

func (*DuplexHTTPCall) ResponseTrailer

func (d *DuplexHTTPCall) ResponseTrailer() http.Header

ResponseTrailer returns the response HTTP trailers.

func (*DuplexHTTPCall) Send

func (d *DuplexHTTPCall) Send(payload MessagePayload) (int64, error)

Send sends a message to the server.

func (*DuplexHTTPCall) SetMethod

func (d *DuplexHTTPCall) SetMethod(method string)

SetMethod changes the method of the request before it is sent.

func (*DuplexHTTPCall) SetValidateResponse

func (d *DuplexHTTPCall) SetValidateResponse(validate func(*http.Response) error)

SetValidateResponse sets the response validation function. The function runs in a background goroutine.

func (*DuplexHTTPCall) Trailer

func (d *DuplexHTTPCall) Trailer() http.Header

Trailer returns the HTTP request trailers.

func (*DuplexHTTPCall) URL

func (d *DuplexHTTPCall) URL() *url.URL

URL returns the URL for the request.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface connect expects HTTP clients to implement. The standard library's *http.Client implements HTTPClient.

type MessagePayload

type MessagePayload interface {
	io.Reader
	io.WriterTo
	io.Seeker
	Len() int
}

MessagePayload is a sized and seekable message payload. The interface is implemented by *bytes.Reader and *envelope. Reads must be non-blocking.

type MessageSender

type MessageSender interface {
	Send(MessagePayload) (int64, error)
}

MessageSender sends a message payload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL