diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-05-01 07:56:25 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-05-01 07:56:25 -0600 |
commit | 9a2da81b11ad0064cca24ce7974827d032309369 (patch) | |
tree | 4313224dc089208423e78bffc3ec50833e35bcea /gemini/request.go | |
parent | 21e2758145d100d74013060f7090d84679cae683 (diff) |
name change gus -> sliderule
Diffstat (limited to 'gemini/request.go')
-rw-r--r-- | gemini/request.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/gemini/request.go b/gemini/request.go index 5220952..51aaae5 100644 --- a/gemini/request.go +++ b/gemini/request.go @@ -6,7 +6,7 @@ import ( "io" "net/url" - "tildegit.org/tjp/gus" + sr "tildegit.org/tjp/sliderule" ) // InvalidRequestLineEnding indicates that a gemini request didn't end with "\r\n". @@ -15,7 +15,7 @@ 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) { +func ParseRequest(rdr io.Reader) (*sr.Request, error) { bufrdr, ok := rdr.(*bufio.Reader) if !ok { bufrdr = bufio.NewReader(rdr) @@ -39,5 +39,19 @@ func ParseRequest(rdr io.Reader) (*gus.Request, error) { u.Scheme = "gemini" } - return &gus.Request{URL: u}, nil + return &sr.Request{URL: u}, nil +} + +// GetTitanRequestBody fetches the request body from a titan request. +// +// It returns nil if the argument is not a titan request or it otherwise +// does not have a request body set. +func GetTitanRequestBody(request *sr.Request) io.Reader { + if request.Scheme != "titan" { + return nil + } + if rdr, ok := request.Meta.(io.Reader); ok { + return rdr + } + return nil } |