From 23d705b93a89cb0aee582eda819a76257f42dffc Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 24 Jan 2023 07:36:28 -0700 Subject: 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. --- gemini/request.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'gemini/request.go') 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 } -- cgit v1.2.3