diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-05-01 07:56:25 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-05-01 07:56:25 -0600 |
commit | 9a2da81b11ad0064cca24ce7974827d032309369 (patch) | |
tree | 4313224dc089208423e78bffc3ec50833e35bcea /spartan/serve.go | |
parent | 21e2758145d100d74013060f7090d84679cae683 (diff) |
name change gus -> sliderule
Diffstat (limited to 'spartan/serve.go')
-rw-r--r-- | spartan/serve.go | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/spartan/serve.go b/spartan/serve.go index 677d76c..61199b1 100644 --- a/spartan/serve.go +++ b/spartan/serve.go @@ -9,27 +9,14 @@ import ( "net" "strings" - "tildegit.org/tjp/gus" - "tildegit.org/tjp/gus/internal" - "tildegit.org/tjp/gus/logging" + sr "tildegit.org/tjp/sliderule" + "tildegit.org/tjp/sliderule/internal" + "tildegit.org/tjp/sliderule/logging" ) -type spartanRequestBodyKey struct{} -type spartanRequestBodyLenKey struct{} - -// SpartanRequestBody is the key set in a handler's context for spartan request bodies. -// -// The corresponding value is a *bufio.Reader from which the request body can be read. -var SpartanRequestBody = spartanRequestBodyKey{} - -// SpartanRequestBodyLen is the key set in a handler's context for the content-length of the request. -// -// The corresponding value is an int. -var SpartanRequestBodyLen = spartanRequestBodyLenKey{} - type spartanServer struct { internal.Server - handler gus.Handler + handler sr.Handler } func (ss spartanServer) Protocol() string { return "SPARTAN" } @@ -40,9 +27,9 @@ func NewServer( hostname string, network string, address string, - handler gus.Handler, + handler sr.Handler, errLog logging.Logger, -) (gus.Server, error) { +) (sr.Server, error) { ss := &spartanServer{handler: handler} if strings.IndexByte(hostname, ':') < 0 { @@ -61,7 +48,7 @@ func NewServer( func (ss *spartanServer) handleConn(conn net.Conn) { buf := bufio.NewReader(conn) - var response *gus.Response + var response *sr.Response request, clen, err := ParseRequest(buf) if err != nil { response = ClientError(err) @@ -69,12 +56,11 @@ func (ss *spartanServer) handleConn(conn net.Conn) { request.Server = ss request.RemoteAddr = conn.RemoteAddr() - var body *bufio.Reader = nil + var body io.Reader = nil if clen > 0 { - body = bufio.NewReader(io.LimitReader(buf, int64(clen))) + body = io.LimitReader(buf, int64(clen)) } - ctx := context.WithValue(ss.Ctx, SpartanRequestBody, body) - ctx = context.WithValue(ctx, SpartanRequestBodyLen, clen) + request.Meta = body defer func() { if r := recover(); r != nil { @@ -84,7 +70,7 @@ func (ss *spartanServer) handleConn(conn net.Conn) { _, _ = io.Copy(conn, rdr) } }() - response = ss.handler.Handle(ctx, request) + response = ss.handler.Handle(ss.Ctx, request) if response == nil { response = ClientError(errors.New("Resource does not exist.")) } |