aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-28 22:07:24 -0500
committerAdnan Maolood <[email protected]>2021-02-28 22:07:24 -0500
commitae7d58549df2e0aa00e35aad3b1d38a1fa6f0e83 (patch)
tree470ba492b4eff2af893972e4327f1c1f8bd12455
parentMention that Request methods don't work for clients (diff)
downloadgo-gemini-ae7d58549df2e0aa00e35aad3b1d38a1fa6f0e83.tar.xz
go-gemini-ae7d58549df2e0aa00e35aad3b1d38a1fa6f0e83.zip
Add message argument to TimeoutHandler
-rw-r--r--handler.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/handler.go b/handler.go
index 58bff5a..ef5df72 100644
--- a/handler.go
+++ b/handler.go
@@ -79,18 +79,21 @@ func StripPrefix(prefix string, h Handler) Handler {
//
// The new Handler calls h.ServeGemini to handle each request, but
// if a call runs for longer than its time limit, the handler responds with a
-// 40 Temporary Failure error. After such a timeout, writes by h to
-// its ResponseWriter will return context.DeadlineExceeded.
-func TimeoutHandler(h Handler, dt time.Duration) Handler {
+// 40 Temporary Failure status code and the given message in its response meta.
+// After such a timeout, writes by h to its ResponseWriter will return
+// context.DeadlineExceeded.
+func TimeoutHandler(h Handler, dt time.Duration, message string) Handler {
return &timeoutHandler{
- h: h,
- dt: dt,
+ h: h,
+ dt: dt,
+ msg: message,
}
}
type timeoutHandler struct {
- h Handler
- dt time.Duration
+ h Handler
+ dt time.Duration
+ msg string
}
func (t *timeoutHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *Request) {
@@ -118,7 +121,7 @@ func (t *timeoutHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *R
w.WriteHeader(tw.status, tw.meta)
w.Write(buf.Bytes())
case <-ctx.Done():
- w.WriteHeader(StatusTemporaryFailure, "Timeout")
+ w.WriteHeader(StatusTemporaryFailure, t.msg)
}
}