summaryrefslogtreecommitdiff
path: root/internal/types/request.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-08-12 09:40:39 -0600
committertjpcc <tjp@ctrl-c.club>2023-08-12 09:40:39 -0600
commit23bc5f4fb7542e64c94eaa7fe2c7a6aa55010898 (patch)
treeec8113d3aa2379e3ca9cb3c6e13a5531895ea8c0 /internal/types/request.go
parent57a31a9b2cd549174d839b9b91b47db337f174cc (diff)
move common types to an internal package
This helps avoid import cycles.
Diffstat (limited to 'internal/types/request.go')
-rw-r--r--internal/types/request.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/types/request.go b/internal/types/request.go
new file mode 100644
index 0000000..e3d2e6f
--- /dev/null
+++ b/internal/types/request.go
@@ -0,0 +1,49 @@
+package types
+
+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
+
+ // Meta is a place for opaque data.
+ //
+ // Look for helper methods in protocol packages to use it appropriately
+ // for the protocol.
+ Meta any
+
+ // 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
+}