From 2ef530daa47b301a40c1ee93cd43b8f36fc68c0b Mon Sep 17 00:00:00 2001 From: tjpcc Date: Tue, 17 Jan 2023 15:59:29 -0700 Subject: pull request, response, handlers out of the gemini package --- request.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 request.go (limited to 'request.go') diff --git a/request.go b/request.go new file mode 100644 index 0000000..1e0f3e7 --- /dev/null +++ b/request.go @@ -0,0 +1,43 @@ +package gus + +import ( + "crypto/tls" + "net" + "net/url" +) + +// Request represents a request over any small web protocol. +// +// Because protocols have so many differences, this type represents a +// greatest common denominator of request/response-oriented protocols. +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 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 +} + +// 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 +} -- cgit v1.2.3