aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-24 19:00:09 -0500
committerAdnan Maolood <[email protected]>2021-02-24 19:00:09 -0500
commit1764e02d1e057139f00a5483a4a2ffa47c9a3079 (patch)
tree94870524cd00fdad3033149378f22a7ae666da8c
parentresponse: Revert to using fields instead of methods (diff)
downloadarchived-go-gemini-1764e02d1e057139f00a5483a4a2ffa47c9a3079.tar.xz
archived-go-gemini-1764e02d1e057139f00a5483a4a2ffa47c9a3079.zip
Remove ResponseWriter.Close method
-rw-r--r--examples/server.go4
-rw-r--r--handler.go17
-rw-r--r--response.go11
3 files changed, 7 insertions, 25 deletions
diff --git a/examples/server.go b/examples/server.go
index 29d5bf1..23bb953 100644
--- a/examples/server.go
+++ b/examples/server.go
@@ -102,7 +102,3 @@ func (w *logResponseWriter) WriteHeader(status gemini.Status, meta string) {
func (w *logResponseWriter) Flush() error {
return nil
}
-
-func (w *logResponseWriter) Close() error {
- return nil
-}
diff --git a/handler.go b/handler.go
index efefcc4..58bff5a 100644
--- a/handler.go
+++ b/handler.go
@@ -14,11 +14,10 @@ import (
// ServeGemini should write the response header and data to the ResponseWriter
// and then return. Returning signals that the request is finished; it is not
// valid to use the ResponseWriter after or concurrently with the completion
-// of the ServeGemini call. Handlers may also call ResponseWriter.Close to
-// manually close the connection.
+// of the ServeGemini call.
//
-// The provided context is canceled when the client's connection is closed,
-// when ResponseWriter.Close is called, or when the ServeGemini method returns.
+// The provided context is canceled when the client's connection is closed
+// or the ServeGemini method returns.
//
// Handlers should not modify the provided Request.
type Handler interface {
@@ -100,7 +99,7 @@ func (t *timeoutHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *R
buf := &bytes.Buffer{}
tw := &timeoutWriter{
- wc: &contextWriter{
+ wr: &contextWriter{
ctx: ctx,
cancel: cancel,
done: ctx.Done(),
@@ -124,7 +123,7 @@ func (t *timeoutHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *R
}
type timeoutWriter struct {
- wc io.WriteCloser
+ wr io.Writer
status Status
meta string
mediatype string
@@ -139,7 +138,7 @@ func (w *timeoutWriter) Write(b []byte) (int, error) {
if !w.wroteHeader {
w.WriteHeader(StatusSuccess, w.mediatype)
}
- return w.wc.Write(b)
+ return w.wr.Write(b)
}
func (w *timeoutWriter) WriteHeader(status Status, meta string) {
@@ -154,7 +153,3 @@ func (w *timeoutWriter) WriteHeader(status Status, meta string) {
func (w *timeoutWriter) Flush() error {
return nil
}
-
-func (w *timeoutWriter) Close() error {
- return w.wc.Close()
-}
diff --git a/response.go b/response.go
index 076b3fa..5c7d7b3 100644
--- a/response.go
+++ b/response.go
@@ -147,10 +147,6 @@ type ResponseWriter interface {
// Flush sends any buffered data to the client.
Flush() error
-
- // Close closes the connection.
- // Any blocked Write operations will be unblocked and return errors.
- Close() error
}
type responseWriter struct {
@@ -161,10 +157,9 @@ type responseWriter struct {
bodyAllowed bool
}
-func newResponseWriter(w io.WriteCloser) *responseWriter {
+func newResponseWriter(w io.Writer) *responseWriter {
return &responseWriter{
bw: bufio.NewWriter(w),
- cl: w,
}
}
@@ -210,7 +205,3 @@ func (w *responseWriter) Flush() error {
// Write errors from WriteHeader will be returned here.
return w.bw.Flush()
}
-
-func (w *responseWriter) Close() error {
- return w.cl.Close()
-}