From 9a2da81b11ad0064cca24ce7974827d032309369 Mon Sep 17 00:00:00 2001 From: tjpcc Date: Mon, 1 May 2023 07:56:25 -0600 Subject: name change gus -> sliderule --- spartan/request.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'spartan/request.go') 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 +} -- cgit v1.2.3