spartan_client

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package spartan_client provides an easy interface to create client and servers that speak the Spartan protocol.

It will automatically handle URLs that have IDNs in them, i.e. 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

View Source
const (
	URLMaxLength  = 1024
	MetaMaxLength = 1024
)
View Source
const (
	StatusSuccess  = 2
	StatusRedirect = 3
	ClientError    = 4
	ServerError    = 5
)

Scroll status codes as defined in the Gemini spec Appendix 1.

Variables

View Source
var DefaultClient = &Client{ConnectTimeout: 15 * time.Second}
View Source
var ISO8601Layout = "2006-01-02T15:04:05Z0700"

Functions

func ContainsLetterRunes

func ContainsLetterRunes(s string) bool

If the string contains any runes of the unicode L (Letter) category, excluding spaces

func CutAny

func CutAny(s string, chars string) (before string, after string, found bool)

CutAny slices s around any Unicode code point from chars, returning the text before and after it. The found result reports whether any Unicode code point was appears in s. If it does not appear in s, CutAny returns s, "", false.

func GetPunycodeURL

func GetPunycodeURL(u string) (string, error)

GetPunycodeURL takes a full URL that potentially has Unicode in the domain name, and returns a URL with the domain punycoded.

func IsStatusValid

func IsStatusValid(status int) bool

IsStatusValid checks whether an int status is covered by the spec. Note that:

A client SHOULD deal with undefined status codes
between '10' and '69' per the default action of the initial digit.

func ParseLines

func ParseLines(reader io.Reader, currentURLString string, lines *[]SpartanLine, headings *[]SpartanLine_Heading, links *[]SpartanLine_Link) (string, bool)

func QueryEscape

func QueryEscape(query string) string

QueryEscape provides URL query escaping in a way that follows the Spartan spec. It is the same as url.PathEscape, but it also replaces the +, because Spartan requires percent-escaping for queries.

func QueryUnescape

func QueryUnescape(query string) (string, error)

QueryUnescape is the same as url.PathUnescape

func StatusInRange

func StatusInRange(status int) bool

StatusInRange returns true if the status has a valid first digit. This means it can be handled even if it's not defined by the spec, because it has a known category

func StatusText

func StatusText(code int) string

StatusText returns a text for the Scroll status code. It returns the empty string if the code is unknown.

Types

type Client

type Client struct {
	// AllowOutOfRangeStatuses means the client won't raise an error if a status
	// that is out of range is returned.
	// Use CleanStatus() to handle statuses that are in range but not specified in
	// the spec.
	AllowOutOfRangeStatuses 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

	// Proxy is a function that returns an existing connection. The TLS client
	// will use this as the underlying transport, instead of making a direct TCP
	// connection.
	//
	// go-gemini requires setting a dialer on the underlying connection, to impose
	// a timeout on making the initial connection. This dialer is provided as an
	// argument to the proxy function.
	//
	// The other argument provided is the address being connected to. For example
	// "example.com:300".
	//
	// Any errors returned will prevent a connection from occurring.
	//
	// This is not "gemini proxying", aka the proxying functionality built in to
	// the Gemini protocol. This is for proxying requests over TOR, or SOCKS5, etc.
	//
	//     func(dialer *net.Dialer, address string) (net.Conn, error)
	//
	Proxy ProxyFunc
}

func (*Client) Request

func (c *Client) Request(rawURL string, data []byte) (*Response, error)

func (*Client) RequestWithHost

func (c *Client) RequestWithHost(host, rawURL string, data []byte) (*Response, error)

Sends a message to a misfin server at the given host, with the given URL. This can be used for misfin proxying, where the URL host and actual server don't match. It assumes the host is using port 300 if no port number is provided.

type Error

type Error struct {
	Err    error
	Status int
}

func (Error) Error

func (e Error) Error() string

func (Error) Unwrap

func (e Error) Unwrap() error

type ProxyFunc

type ProxyFunc func(dialer *net.Dialer, address string) (net.Conn, error)

ProxyFunc. See Client documentation

type Response

type Response struct {
	Status int
	Meta   string        // Input Prompt, Error Description, or Success Mimetype w/ Language
	Body   io.ReadCloser // Use to get resource data (or abstract for metadata requests)
	// contains filtered or unexported fields
}

Response represents the response from a Scroll server.

func Request

func Request(rawURL string, data []byte) (*Response, error)

func RequestWithHost

func RequestWithHost(host, url string, data []byte) (*Response, error)

Sends a message to a misfin server at the given host, with the given URL. This can be used for misfin proxying, where the URL host and actual server don't match. It assumes the host is using port 300 if no port number is provided.

type SpartanLine

type SpartanLine interface {
	String() string
	ImplementsScrollLine()
}

type SpartanLine_Heading

type SpartanLine_Heading struct {
	Level int
	Text  string
}

func (SpartanLine_Heading) ImplementsScrollLine

func (heading SpartanLine_Heading) ImplementsScrollLine()

func (SpartanLine_Heading) String

func (heading SpartanLine_Heading) String() string
type SpartanLine_Link struct {
	Url      string
	Title    string
	Relation int
	Tag      string
	Input    bool
	Time     time.Time
}

func (SpartanLine_Link) ImplementsScrollLine

func (link SpartanLine_Link) ImplementsScrollLine()

func (SpartanLine_Link) String

func (link SpartanLine_Link) String() string

type SpartanLine_OrderedListItem

type SpartanLine_OrderedListItem struct {
	Level int
	Label string
	Text  string
}

func (SpartanLine_OrderedListItem) ImplementsScrollLine

func (listItem SpartanLine_OrderedListItem) ImplementsScrollLine()

func (SpartanLine_OrderedListItem) String

func (listItem SpartanLine_OrderedListItem) String() string

type SpartanLine_PreformattedText

type SpartanLine_PreformattedText string

func (SpartanLine_PreformattedText) ImplementsScrollLine

func (preformattedText SpartanLine_PreformattedText) ImplementsScrollLine()

func (SpartanLine_PreformattedText) String

func (preformattedText SpartanLine_PreformattedText) String() string

type SpartanLine_PreformattedToggle

type SpartanLine_PreformattedToggle string

func (SpartanLine_PreformattedToggle) ImplementsScrollLine

func (preformattedToggle SpartanLine_PreformattedToggle) ImplementsScrollLine()

func (SpartanLine_PreformattedToggle) String

func (preformattedToggle SpartanLine_PreformattedToggle) String() string

type SpartanLine_Quote

type SpartanLine_Quote struct {
	Level int
	Text  string
}

func (SpartanLine_Quote) ImplementsScrollLine

func (quote SpartanLine_Quote) ImplementsScrollLine()

func (SpartanLine_Quote) String

func (quote SpartanLine_Quote) String() string

type SpartanLine_Text

type SpartanLine_Text string

func (SpartanLine_Text) ImplementsScrollLine

func (text SpartanLine_Text) ImplementsScrollLine()

func (SpartanLine_Text) String

func (text SpartanLine_Text) String() string

type SpartanLine_UnorderedListItem

type SpartanLine_UnorderedListItem struct {
	Level int
	Text  string
}

func (SpartanLine_UnorderedListItem) ImplementsScrollLine

func (listItem SpartanLine_UnorderedListItem) ImplementsScrollLine()

func (SpartanLine_UnorderedListItem) String

func (listItem SpartanLine_UnorderedListItem) String() string

type TextParsingState

type TextParsingState struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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