summaryrefslogtreecommitdiff
path: root/spartan/request.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-05-01 07:56:25 -0600
committertjpcc <tjp@ctrl-c.club>2023-05-01 07:56:25 -0600
commit9a2da81b11ad0064cca24ce7974827d032309369 (patch)
tree4313224dc089208423e78bffc3ec50833e35bcea /spartan/request.go
parent21e2758145d100d74013060f7090d84679cae683 (diff)
name change gus -> sliderule
Diffstat (limited to 'spartan/request.go')
-rw-r--r--spartan/request.go26
1 files changed, 23 insertions, 3 deletions
diff --git a/spartan/request.go b/spartan/request.go
index ca1159b..a9b2815 100644
--- a/spartan/request.go
+++ b/spartan/request.go
@@ -8,7 +8,7 @@ import (
"strconv"
"strings"
- "tildegit.org/tjp/gus"
+ sr "tildegit.org/tjp/sliderule"
)
var (
@@ -22,7 +22,7 @@ var (
// ParseRequest parses a single spartan request and the indicated content-length from a reader.
//
// If ther reader artument is a *bufio.Reader, it will only read a single line from it.
-func ParseRequest(rdr io.Reader) (*gus.Request, int, error) {
+func ParseRequest(rdr io.Reader) (*sr.Request, int, error) {
bufrdr, ok := rdr.(*bufio.Reader)
if !ok {
bufrdr = bufio.NewReader(rdr)
@@ -51,7 +51,7 @@ func ParseRequest(rdr io.Reader) (*gus.Request, int, error) {
return nil, 0, err
}
- return &gus.Request{
+ return &sr.Request{
URL: &url.URL{
Scheme: "spartan",
Host: host,
@@ -60,3 +60,23 @@ func ParseRequest(rdr io.Reader) (*gus.Request, int, error) {
},
}, contentlen, nil
}
+
+// GetRequestContentLength reads the remaining un-read number of bytes in a request body.
+//
+// It will immediately return 0 if there is no request body.
+func GetRequestContentLength(request *sr.Request) int {
+ if lr, ok := request.Meta.(*io.LimitedReader); ok {
+ return int(lr.N)
+ }
+ return 0
+}
+
+// GetRequestBody returns a reader of the spartan request body.
+//
+// It will return nil if the request has no body.
+func GetRequestBody(request *sr.Request) io.Reader {
+ if rdr, ok := request.Meta.(io.Reader); ok {
+ return rdr
+ }
+ return nil
+}