summaryrefslogtreecommitdiff
path: root/spartan/request.go
diff options
context:
space:
mode:
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
+}