summaryrefslogtreecommitdiff
path: root/gemini/request.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-01-17 15:59:29 -0700
committertjpcc <tjp@ctrl-c.club>2023-01-17 15:59:29 -0700
commit2ef530daa47b301a40c1ee93cd43b8f36fc68c0b (patch)
treeb9753719f5f0e5312bb5008d40f40247ce14e15a /gemini/request.go
parent30e21f8513d49661cb6e1583d301e34e898d48a9 (diff)
pull request, response, handlers out of the gemini package
Diffstat (limited to 'gemini/request.go')
-rw-r--r--gemini/request.go41
1 files changed, 4 insertions, 37 deletions
diff --git a/gemini/request.go b/gemini/request.go
index 933281b..ced7d0b 100644
--- a/gemini/request.go
+++ b/gemini/request.go
@@ -2,43 +2,18 @@ package gemini
import (
"bufio"
- "crypto/tls"
"errors"
"io"
- "net"
"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")
-// Request represents a request over the gemini protocol.
-type Request struct {
- // URL is the specific URL being fetched by the request.
- *url.URL
-
- // Server is the server which received the request.
- //
- // This is only populated in gemini servers.
- // It is unused on the client end.
- Server *Server
-
- // RemoteAddr is the address of the other side of the connection.
- //
- // This will be the server address for clients, or the connecting
- // client's address in servers.
- //
- // Be aware though that proxies (and reverse proxies) can confuse this.
- RemoteAddr net.Addr
-
- // TLSState contains information about the TLS encryption over the connection.
- //
- // This includes peer certificates and version information.
- TLSState *tls.ConnectionState
-}
-
// ParseRequest parses a single gemini request from a reader.
-func ParseRequest(rdr io.Reader) (*Request, error) {
+func ParseRequest(rdr io.Reader) (*gus.Request, error) {
line, err := bufio.NewReader(rdr).ReadString('\n')
if err != io.EOF && err != nil {
return nil, err
@@ -57,13 +32,5 @@ func ParseRequest(rdr io.Reader) (*Request, error) {
u.Scheme = "gemini"
}
- return &Request{URL: u}, nil
-}
-
-// UnescapedQuery performs %XX unescaping on the URL query segment.
-//
-// Like URL.Query(), it silently drops malformed %-encoded sequences.
-func (req Request) UnescapedQuery() string {
- unescaped, _ := url.QueryUnescape(req.RawQuery)
- return unescaped
+ return &gus.Request{URL: u}, nil
}