diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-10-10 08:59:21 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-10-10 09:02:09 -0600 |
commit | aa15254e73d04916bead2f2743df55699987adac (patch) | |
tree | 2812e0566c94ff643ed0a8b3c2cb2d70bf189b73 | |
parent | c38b7ad69d738281e6569e447e8d3e634097d9a4 (diff) |
gofmt + allow finger requests without CRLF line ending
-rw-r--r-- | finger/request.go | 20 | ||||
-rw-r--r-- | finger/serve.go | 2 |
2 files changed, 8 insertions, 14 deletions
diff --git a/finger/request.go b/finger/request.go index 5eae6b6..14058ca 100644 --- a/finger/request.go +++ b/finger/request.go @@ -13,18 +13,15 @@ import ( // ForwardingDenied is returned in response to requests for forwarding service. var ForwardingDenied = errors.New("Finger forwarding service denied.") -// InvalidFingerQuery is sent when a client doesn't properly format the query. -var InvalidFingerQuery = errors.New("Invalid finger query.") - // ParseRequest builds a sliderule.Request by reading a finger protocol request. // // At the time of writing, there is no firm standard on how to represent finger // queries as URLs (the finger protocol itself predates URLs entirely), but there // are a few helpful resources to go from. -// - The lynx browser supports finger URLs and documents the forms they may take: -// https://lynx.invisible-island.net/lynx_help/lynx_url_support.html#finger_url -// - There is an IETF draft: -// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger +// - The lynx browser supports finger URLs and documents the forms they may take: +// https://lynx.invisible-island.net/lynx_help/lynx_url_support.html#finger_url +// - There is an IETF draft: +// https://datatracker.ietf.org/doc/html/draft-ietf-uri-url-finger // // As this function builds a *sliderule.Request (which is mostly a wrapper around a URL) // from nothing but an io.Reader, it doesn't have the context of the hostname which @@ -53,13 +50,10 @@ func ParseRequest(rdr io.Reader) (*types.Request, error) { return nil, err } - if len(line) < 2 || line[len(line)-2] != '\r' { - return nil, InvalidFingerQuery - } - - line = strings.TrimSuffix(line, "\r\n") + line = strings.TrimRight(line, " \t\r\n") + line = strings.TrimLeft(line, " \t") line = strings.TrimPrefix(line, "/W") - line = strings.TrimLeft(line, " ") + line = strings.TrimLeft(line, " \t") username, hostname, _ := strings.Cut(line, "@") if strings.Contains(hostname, "@") { diff --git a/finger/serve.go b/finger/serve.go index db96088..f959373 100644 --- a/finger/serve.go +++ b/finger/serve.go @@ -6,8 +6,8 @@ import ( "io" "net" - "tildegit.org/tjp/sliderule/internal/types" "tildegit.org/tjp/sliderule/internal" + "tildegit.org/tjp/sliderule/internal/types" "tildegit.org/tjp/sliderule/logging" ) |