client

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MPL-2.0 Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoBody = errors.New("Response has no body")

The response was attempted to be read, but there is no body

Functions

This section is empty.

Types

type Request

type Request struct {
	// Method of the request
	Method gmitools.Method
	// Host of the request. This includes the port if applicable
	Host string
	// Path component
	Path string
	// Query component without question mark
	Query string
	// Token to send if this is a titan request
	Token string
	// Content type of the body if this is a titan request
	ContentType string
	// Body to send if this is a titan request
	Body io.Reader
	// The size of the body
	Size int64
	// Client certificate to send
	Cert *tls.Certificate
}

Client request struct

The information that will be sent with a gemini client request

func NewReq

func NewReq(uri string) (*Request, error)

Create a new request given a url string

func (*Request) HostName

func (self *Request) HostName() string

Get the host name without the port

func (*Request) LoadCert

func (self *Request) LoadCert(cert *x509.Certificate, key crypto.Signer) error

Load the client certificate from a certificate and signer

func (*Request) LoadCertKey

func (self *Request) LoadCertKey(certPem []byte, keyPem []byte) error

Load the client certificate from PEM encoded bodies

func (*Request) LoadCertKeyFiles

func (self *Request) LoadCertKeyFiles(certPath string, keyPath string) error

Load the client certificate from PEM encoded files

func (*Request) Send

func (self *Request) Send(config ...*tls.Config) (response Response, err error)

Send the request

config is an optional tls Configuration

func (*Request) SendWithTimeout

func (self *Request) SendWithTimeout(timeout time.Duration, config ...*tls.Config) (response Response, err error)

Send the request with a connection timeout

Once the connection has been made, the request will wait until the server closes the connection ignoring the timeout.

config is an optional tls Configuration

func (*Request) SetBody

func (self *Request) SetBody(body io.Reader, size ...int64) error

Set the body of the titan request

size is an optional parameter. If it is not provided, then the size will be determined from the body.

The body will be read into memory if size is not supplied and body is not also a seeker.

func (*Request) SetDelete

func (self *Request) SetDelete()

Set the titan request to be a delete operation.

func (*Request) Url

func (self *Request) Url() (*url.URL, error)

Get the url object that the request will make

func (*Request) UrlString

func (self *Request) UrlString() string

Get the full url string that the request will make

type Response

type Response struct {
	// The returned status code
	Status gmitools.StatusCode
	// The meta value
	Meta string
	// The body of the response
	Body io.ReadCloser
	// The tls connection state of the response
	State tls.ConnectionState
}

Gemini Response struct

The response should be closed when done.

func (*Response) Close

func (self *Response) Close() error

func (*Response) HasBody

func (self *Response) HasBody() bool

Check if the response has a body

func (*Response) IsCertFail

func (self *Response) IsCertFail() bool

Check if the response is in the certificate failure class (6X)

func (*Response) IsInput

func (self *Response) IsInput() bool

Check if the response is in then input class (1X)

func (*Response) IsPermFail

func (self *Response) IsPermFail() bool

Check if the response is in the permanent failure class (5X)

func (*Response) IsRedirect

func (self *Response) IsRedirect() bool

Check if the response is in the redirect class (3X)

func (*Response) IsSuccess

func (self *Response) IsSuccess() bool

Check if the response is in the success class (2X)

func (*Response) IsTempFail

func (self *Response) IsTempFail() bool

Check if the response is in the temporary failure class (4X)

func (*Response) Read

func (self *Response) Read(d []byte) (int, error)

Jump to

Keyboard shortcuts

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