summaryrefslogtreecommitdiff
path: root/gemini/serve.go
diff options
context:
space:
mode:
Diffstat (limited to 'gemini/serve.go')
-rw-r--r--gemini/serve.go32
1 files changed, 11 insertions, 21 deletions
diff --git a/gemini/serve.go b/gemini/serve.go
index 2f93153..01e186f 100644
--- a/gemini/serve.go
+++ b/gemini/serve.go
@@ -11,23 +11,17 @@ import (
"strconv"
"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 titanRequestBodyKey struct{}
-// TitanRequestBody is the key set in a handler's context for titan requests.
-//
-// When this key is present in the context (request.URL.Scheme will be "titan"), the
-// corresponding value is a *bufio.Reader from which the request body can be read.
-var TitanRequestBody = titanRequestBodyKey{}
-
type server struct {
internal.Server
- handler gus.Handler
+ handler sr.Handler
}
func (s server) Protocol() string { return "GEMINI" }
@@ -38,10 +32,10 @@ func NewServer(
hostname string,
network string,
address string,
- handler gus.Handler,
+ handler sr.Handler,
errorLog logging.Logger,
tlsConfig *tls.Config,
-) (gus.Server, error) {
+) (sr.Server, error) {
s := &server{handler: handler}
if strings.IndexByte(hostname, ':') < 0 {
@@ -62,7 +56,7 @@ func NewServer(
func (s *server) handleConn(conn net.Conn) {
buf := bufio.NewReader(conn)
- var response *gus.Response
+ var response *sr.Response
request, err := ParseRequest(buf)
if err != nil {
response = BadRequest(err.Error())
@@ -79,11 +73,7 @@ func (s *server) handleConn(conn net.Conn) {
if request.Scheme == "titan" {
len, err := sizeParam(request.Path)
if err == nil {
- ctx = context.WithValue(
- ctx,
- TitanRequestBody,
- io.LimitReader(buf, int64(len)),
- )
+ request.Meta = io.LimitReader(buf, int64(len))
}
}
@@ -125,9 +115,9 @@ func sizeParam(path string) (int, error) {
// Optionally, it will also allow through titan:// requests.
//
// Filtered requests will be turned away with a 53 response "proxy request refused".
-func GeminiOnly(allowTitan bool) gus.Middleware {
- return func(inner gus.Handler) gus.Handler {
- return gus.HandlerFunc(func(ctx context.Context, request *gus.Request) *gus.Response {
+func GeminiOnly(allowTitan bool) sr.Middleware {
+ return func(inner sr.Handler) sr.Handler {
+ return sr.HandlerFunc(func(ctx context.Context, request *sr.Request) *sr.Response {
if request.Scheme == "gemini" || (allowTitan && request.Scheme == "titan") {
return inner.Handle(ctx, request)
}