package gemini import ( "bufio" "errors" "io" "net/url" "tildegit.org/tjp/gus" ) // InvalidRequestLineEnding indicates that a gemini request didn't end with "\r\n". var InvalidRequestLineEnding = errors.New("invalid request line ending") // ParseRequest parses a single gemini request from a reader. func ParseRequest(rdr io.Reader) (*gus.Request, error) { line, err := bufio.NewReader(rdr).ReadString('\n') if err != io.EOF && err != nil { return nil, err } if len(line) < 2 || line[len(line)-2:] != "\r\n" { return nil, InvalidRequestLineEnding } u, err := url.Parse(line[:len(line)-2]) if err != nil { return nil, err } if u.Scheme == "" { u.Scheme = "gemini" } return &gus.Request{URL: u}, nil }