diff options
author | tjp <tjp@ctrl-c.club> | 2025-04-03 09:32:22 -0600 |
---|---|---|
committer | tjp <tjp@ctrl-c.club> | 2025-04-03 09:59:24 -0600 |
commit | 74bbf67ebbd1325ff699a052933ad94bc0401c58 (patch) | |
tree | a9be5180163430e6e023ecd9769477e939224e09 | |
parent | 2e5ac8b9e1f2f705455d74750e465c2066ffdc7c (diff) |
-rw-r--r-- | client.go | 6 | ||||
-rw-r--r-- | gemini/client.go | 4 | ||||
-rw-r--r-- | gemini/request.go | 6 | ||||
-rw-r--r-- | gemini/request_test.go | 2 | ||||
-rw-r--r-- | gemini/response.go | 16 | ||||
-rw-r--r-- | gemini/response_test.go | 8 | ||||
-rw-r--r-- | spartan/client.go | 2 | ||||
-rw-r--r-- | spartan/request.go | 12 | ||||
-rw-r--r-- | spartan/response.go | 14 | ||||
-rw-r--r-- | spartan/serve.go | 4 |
10 files changed, 37 insertions, 37 deletions
@@ -31,7 +31,7 @@ type Client struct { const DefaultMaxRedirects int = 5 -var ExceededMaxRedirects = errors.New("Client: exceeded MaxRedirects") +var ErrExceededMaxRedirects = errors.New("Client: exceeded MaxRedirects") // NewClient builds a Client object. // @@ -96,7 +96,7 @@ func (c Client) Fetch(ctx context.Context, url string) (*Response, error) { } } - return nil, ExceededMaxRedirects + return nil, ErrExceededMaxRedirects } // Upload sends a request with a body and returns any redirect response. @@ -130,7 +130,7 @@ type httpClient struct { func (hc httpClient) RoundTrip(ctx context.Context, request *Request) (*Response, error) { body, _ := request.Meta.(io.Reader) - hreq, err := http.NewRequestWithContext(ctx, "GET", request.URL.String(), body) + hreq, err := http.NewRequestWithContext(ctx, "GET", request.String(), body) if err != nil { return nil, err } diff --git a/gemini/client.go b/gemini/client.go index e0f70e4..54fa069 100644 --- a/gemini/client.go +++ b/gemini/client.go @@ -41,7 +41,7 @@ func NewClient(tlsConf *tls.Config) Client { // single request by default. This can be changed by altering the MaxRedirects field. const DefaultMaxRedirects int = 2 -var ExceededMaxRedirects = errors.New("gemini.Client: exceeded MaxRedirects") +var ErrExceededMaxRedirects = errors.New("gemini.Client: exceeded MaxRedirects") // RoundTrip sends a single gemini request to the correct server and returns its response. // @@ -152,7 +152,7 @@ func (c Client) Fetch(ctx context.Context, url string) (*types.Response, error) u = prev.ResolveReference(u) } - return nil, ExceededMaxRedirects + return nil, ErrExceededMaxRedirects } func (c Client) IsRedirect(response *types.Response) bool { diff --git a/gemini/request.go b/gemini/request.go index 8fa1e40..4d75381 100644 --- a/gemini/request.go +++ b/gemini/request.go @@ -11,8 +11,8 @@ import ( "tildegit.org/tjp/sliderule/internal/types" ) -// InvalidRequestLineEnding indicates that a gemini request didn't end with "\r\n". -var InvalidRequestLineEnding = errors.New("invalid request line ending") +// ErrInvalidRequestLineEnding indicates that a gemini request didn't end with "\r\n". +var ErrInvalidRequestLineEnding = errors.New("invalid request line ending") // ParseRequest parses a single gemini/titan request from a reader. // @@ -29,7 +29,7 @@ func ParseRequest(rdr io.Reader) (*types.Request, error) { } if len(line) < 2 || line[len(line)-2:] != "\r\n" { - return nil, InvalidRequestLineEnding + return nil, ErrInvalidRequestLineEnding } u, err := url.Parse(line[:len(line)-2]) diff --git a/gemini/request_test.go b/gemini/request_test.go index a2b1830..01831d7 100644 --- a/gemini/request_test.go +++ b/gemini/request_test.go @@ -51,7 +51,7 @@ func TestParseRequest(t *testing.T) { path: "", query: "", fragment: "", - err: gemini.InvalidRequestLineEnding, + err: gemini.ErrInvalidRequestLineEnding, }, } diff --git a/gemini/response.go b/gemini/response.go index ec4ac2b..940dc35 100644 --- a/gemini/response.go +++ b/gemini/response.go @@ -293,11 +293,11 @@ func StatusName(status types.Status) string { } } -// InvalidResponseLineEnding indicates that a gemini response header didn't end with "\r\n". -var InvalidResponseLineEnding = errors.New("Invalid response line ending.") +// ErrInvalidResponseLineEnding indicates that a gemini response header didn't end with "\r\n". +var ErrInvalidResponseLineEnding = errors.New("invalid response line ending") -// InvalidResponseHeaderLine indicates a malformed gemini response header line. -var InvalidResponseHeaderLine = errors.New("Invalid response header line.") +// ErrInvalidResponseHeaderLine indicates a malformed gemini response header line. +var ErrInvalidResponseHeaderLine = errors.New("invalid response header line") // ParseResponse parses a complete gemini response from a reader. // @@ -307,19 +307,19 @@ func ParseResponse(rdr io.Reader) (*types.Response, error) { hdrLine, err := bufrdr.ReadBytes('\n') if err != nil { - return nil, InvalidResponseLineEnding + return nil, ErrInvalidResponseLineEnding } if hdrLine[len(hdrLine)-2] != '\r' { - return nil, InvalidResponseLineEnding + return nil, ErrInvalidResponseLineEnding } if hdrLine[2] != ' ' { - return nil, InvalidResponseHeaderLine + return nil, ErrInvalidResponseHeaderLine } hdrLine = hdrLine[:len(hdrLine)-2] status, err := strconv.Atoi(string(hdrLine[:2])) if err != nil { - return nil, InvalidResponseHeaderLine + return nil, ErrInvalidResponseHeaderLine } return &types.Response{ diff --git a/gemini/response_test.go b/gemini/response_test.go index 784e00a..9ab9da6 100644 --- a/gemini/response_test.go +++ b/gemini/response_test.go @@ -172,19 +172,19 @@ func TestParseResponses(t *testing.T) { }, { input: "10 forgot the line ending", - err: gemini.InvalidResponseLineEnding, + err: gemini.ErrInvalidResponseLineEnding, }, { input: "10 wrong line ending\n", - err: gemini.InvalidResponseLineEnding, + err: gemini.ErrInvalidResponseLineEnding, }, { input: "10no space\r\n", - err: gemini.InvalidResponseHeaderLine, + err: gemini.ErrInvalidResponseHeaderLine, }, { input: "no status code\r\n", - err: gemini.InvalidResponseHeaderLine, + err: gemini.ErrInvalidResponseHeaderLine, }, { input: "31 gemini://domain.com/my/new/home\r\n", diff --git a/spartan/client.go b/spartan/client.go index aff9276..37cb45d 100644 --- a/spartan/client.go +++ b/spartan/client.go @@ -134,6 +134,6 @@ func (c Client) IsRedirect(response *types.Response) bool { type devnull struct{} -func (_ devnull) Read(p []byte) (int, error) { +func (devnull) Read(p []byte) (int, error) { return 0, nil } diff --git a/spartan/request.go b/spartan/request.go index aa696fa..b35fd77 100644 --- a/spartan/request.go +++ b/spartan/request.go @@ -12,11 +12,11 @@ import ( ) var ( - // InvalidRequestLine indicates a malformed first-line of a spartan request. - InvalidRequestLine = errors.New("invalid request line") + // ErrInvalidRequestLine indicates a malformed first-line of a spartan request. + ErrInvalidRequestLine = errors.New("invalid request line") - // InvalidRequestLineEnding says that a spartan request's first line wasn't terminated with CRLF. - InvalidRequestLineEnding = errors.New("invalid request line ending") + // ErrInvalidRequestLineEnding says that a spartan request's first line wasn't terminated with CRLF. + ErrInvalidRequestLineEnding = errors.New("invalid request line ending") ) // ParseRequest parses a single spartan request and the indicated content-length from a reader. @@ -37,11 +37,11 @@ func ParseRequest(rdr io.Reader) (*types.Request, int, error) { host, rest, ok := strings.Cut(line, " ") if !ok { - return nil, 0, InvalidRequestLine + return nil, 0, ErrInvalidRequestLine } path, rest, ok := strings.Cut(rest, " ") if !ok || len(rest) == 0 { - return nil, 0, InvalidRequestLine + return nil, 0, ErrInvalidRequestLine } u, err := url.Parse(path) diff --git a/spartan/response.go b/spartan/response.go index df565f9..a71c598 100644 --- a/spartan/response.go +++ b/spartan/response.go @@ -52,26 +52,26 @@ func ServerError(err error) *types.Response { } } -// InvalidResponseHeaderLine indicates a malformed spartan response line. -var InvalidResponseHeaderLine = errors.New("Invalid response header line.") +// ErrInvalidResponseHeaderLine indicates a malformed spartan response line. +var ErrInvalidResponseHeaderLine = errors.New("invalid response header line") -// InvalidResponseLineEnding indicates that a spartan response header didn't end with "\r\n". -var InvalidResponseLineEnding = errors.New("Invalid response line ending.") +// ErrInvalidResponseLineEnding indicates that a spartan response header didn't end with "\r\n". +var ErrInvalidResponseLineEnding = errors.New("invalid response line ending") func ParseResponse(rdr io.Reader) (*types.Response, error) { bufrdr := bufio.NewReader(rdr) hdrLine, err := bufrdr.ReadString('\n') if err != nil { - return nil, InvalidResponseLineEnding + return nil, ErrInvalidResponseLineEnding } if len(hdrLine) < 2 { - return nil, InvalidResponseHeaderLine + return nil, ErrInvalidResponseHeaderLine } status, err := strconv.Atoi(string(hdrLine[0])) if err != nil || hdrLine[1] != ' ' || hdrLine[len(hdrLine)-2:] != "\r\n" { - return nil, InvalidResponseHeaderLine + return nil, ErrInvalidResponseHeaderLine } return &types.Response{ diff --git a/spartan/serve.go b/spartan/serve.go index 9403a15..354c1e1 100644 --- a/spartan/serve.go +++ b/spartan/serve.go @@ -58,13 +58,13 @@ func (ss *spartanServer) handleConn(conn net.Conn) { if r := recover(); r != nil { err := fmt.Errorf("%s", r) _ = ss.LogError("msg", "panic in handler", "err", err) - rdr := NewResponseReader(ServerError(errors.New("Server error"))) + rdr := NewResponseReader(ServerError(errors.New("server error"))) _, _ = io.Copy(conn, rdr) } }() response = ss.handler.Handle(ss.Ctx, request) if response == nil { - response = ClientError(errors.New("Resource does not exist.")) + response = ClientError(errors.New("resource does not exist")) } } |