Documentation
¶
Overview ¶
Package gemini provides an easy interface to create client and servers that speak the Gemini protocol.
At the moment, this library is client-side only, and support is not guaranteed. It is mostly a personal library.
It will automatically handle URLs that have IDNs in them, ie domains with Unicode. It will convert to punycode for DNS and for sending to the server, but accept certs with either punycode or Unicode as the hostname.
This also applies to hosts, for functions where a host can be passed specifically.
Index ¶
- Constants
- Variables
- func GetPunycodeURL(u string) (string, error)
- func IsStatusValid(status int) bool
- func QueryEscape(query string) string
- func QueryUnescape(query string) (string, error)
- func SimplifyStatus(status int) int
- type Client
- func (c *Client) Fetch(rawURL string) (*Response, error)
- func (c *Client) FetchWithCert(rawURL string, certPEM, keyPEM []byte) (*Response, error)
- func (c *Client) FetchWithHost(host, rawURL string) (*Response, error)
- func (c *Client) FetchWithHostAndCert(host, rawURL string, certPEM, keyPEM []byte) (*Response, error)
- type Error
- type Response
Constants ¶
const ( URLMaxLength = 1024 MetaMaxLength = 1024 )
const ( StatusInput = 10 StatusSensitiveInput = 11 StatusSuccess = 20 StatusRedirect = 30 StatusRedirectTemporary = 30 StatusRedirectPermanent = 31 StatusTemporaryFailure = 40 StatusCGIError = 42 StatusProxyError = 43 StatusSlowDown = 44 StatusPermanentFailure = 50 StatusNotFound = 51 StatusGone = 52 StatusProxyRequestRefused = 53 StatusBadRequest = 59 StatusClientCertificateRequired = 60 StatusCertificateNotAuthorised = 61 StatusCertificateNotValid = 62 )
Gemini status codes as defined in the Gemini spec Appendix 1.
Variables ¶
var DefaultClient = &Client{ConnectTimeout: 15 * time.Second}
Functions ¶
func GetPunycodeURL ¶
GetPunycodeURL takes a full URL that potentially has Unicode in the domain name, and returns a URL with the domain punycoded.
func IsStatusValid ¶
IsStatusValid checks whether an int status is covered by the spec.
func QueryEscape ¶
QueryEscape provides URL query escaping in a way that follows the Gemini spec. It is the same as url.PathEscape, but it also replaces the +, because Gemini requires percent-escaping for queries.
func QueryUnescape ¶
QueryUnescape is the same as url.PathUnescape
func SimplifyStatus ¶
SimplifyStatus simplify the response status by omiting the detailed second digit of the status code.
Types ¶
type Client ¶
type Client struct { // NoTimeCheck allows connections with expired or future certs if set to true. NoTimeCheck bool // NoHostnameCheck allows connections when the cert doesn't match the // requested hostname or IP. NoHostnameCheck bool // Insecure disables all TLS-based checks, use with caution. // It overrides all the variables above. Insecure bool // AllowInvalidStatuses means the client won't raise an error if a status // that is out of spec is returned. AllowInvalidStatuses bool // ConnectTimeout is equivalent to the Timeout field in net.Dialer. // It's the max amount of time allowed for the initial connection/handshake. // The timeout of the DefaultClient is 15 seconds. // // If ReadTimeout is not set, then this value is also used to time out on getting // the header after the connection is made. ConnectTimeout time.Duration // ReadTimeout is the max amount of time reading to a server can take. // This should not be set if you want to support streams. // It is equivalent to net.Conn.SetDeadline, see that func for more documentation. // // For example, if this is set to 30 seconds, then no more reading from the connection // can happen 30 seconds after the initial handshake. ReadTimeout time.Duration }
func (*Client) Fetch ¶
Fetch a resource from a Gemini server with the given URL. It assumes port 1965 if no port is specified.
func (*Client) FetchWithCert ¶
FetchWithCert fetches a resource from a Gemini server with the given URL. It allows you to provide the bytes of a PEM encoded block for a client certificate and its key. This allows you to make requests using client certs.
It assumes port 1965 if no port is specified.
func (*Client) FetchWithHost ¶
FetchWithHost fetches a resource from a Gemini server at the given host, with the given URL. This can be used for proxying, where the URL host and actual server don't match. It assumes the host is using port 1965 if no port number is provided.
type Response ¶
type Response struct { Status int Meta string Body io.ReadCloser Cert *x509.Certificate // contains filtered or unexported fields }
Response represents the response from a Gemini server.
func Fetch ¶
Fetch a resource from a Gemini server with the given URL. It assumes port 1965 if no port is specified.
func FetchWithCert ¶
FetchWithCert fetches a resource from a Gemini server with the given URL. It allows you to provide the bytes of a PEM encoded block for a client certificate and its key. This allows you to make requests using client certs.
It assumes port 1965 if no port is specified.
func FetchWithHost ¶
FetchWithHost fetches a resource from a Gemini server at the given host, with the given URL. This can be used for proxying, where the URL host and actual server don't match. It assumes the host is using port 1965 if no port number is provided.
func FetchWithHostAndCert ¶
FetchWithHostAndCert combines FetchWithHost and FetchWithCert.