diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-01-24 07:36:28 -0700 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-01-24 07:36:28 -0700 |
commit | 23d705b93a89cb0aee582eda819a76257f42dffc (patch) | |
tree | 94091c5915a9c1dc9914622838394d32dccf2fed /gemini/request.go | |
parent | 0480e066a3f1ae97dbab8fcb6303589eb0fa724c (diff) |
Add support for titan:// to the gemini server
Titan is a gemini add-on protocol so it really didn't make sense to
build it out in a separate package. The most significant difference in
titan for the purposes of implementation here is that requests can have
bodies following the URL line.
Since gus.Request is a struct, the only way to smuggle in the new field
(a reader for the body) was to stash it in the context.
Diffstat (limited to 'gemini/request.go')
-rw-r--r-- | gemini/request.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gemini/request.go b/gemini/request.go index ced7d0b..5220952 100644 --- a/gemini/request.go +++ b/gemini/request.go @@ -13,8 +13,15 @@ import ( var InvalidRequestLineEnding = errors.New("invalid request line ending") // ParseRequest parses a single gemini request from a reader. +// +// If the reader argument is a *bufio.Reader, it will only read a single line from it. func ParseRequest(rdr io.Reader) (*gus.Request, error) { - line, err := bufio.NewReader(rdr).ReadString('\n') + bufrdr, ok := rdr.(*bufio.Reader) + if !ok { + bufrdr = bufio.NewReader(rdr) + } + + line, err := bufrdr.ReadString('\n') if err != io.EOF && err != nil { return nil, err } |