Remove ResponseWriter.Close method

This commit is contained in:
Adnan Maolood 2021-02-24 19:00:09 -05:00
parent 1bc5c68c3f
commit 1764e02d1e
3 changed files with 7 additions and 25 deletions

View File

@ -102,7 +102,3 @@ func (w *logResponseWriter) WriteHeader(status gemini.Status, meta string) {
func (w *logResponseWriter) Flush() error { func (w *logResponseWriter) Flush() error {
return nil return nil
} }
func (w *logResponseWriter) Close() error {
return nil
}

View File

@ -14,11 +14,10 @@ import (
// ServeGemini should write the response header and data to the ResponseWriter // ServeGemini should write the response header and data to the ResponseWriter
// and then return. Returning signals that the request is finished; it is not // and then return. Returning signals that the request is finished; it is not
// valid to use the ResponseWriter after or concurrently with the completion // valid to use the ResponseWriter after or concurrently with the completion
// of the ServeGemini call. Handlers may also call ResponseWriter.Close to // of the ServeGemini call.
// manually close the connection.
// //
// The provided context is canceled when the client's connection is closed, // The provided context is canceled when the client's connection is closed
// when ResponseWriter.Close is called, or when the ServeGemini method returns. // or the ServeGemini method returns.
// //
// Handlers should not modify the provided Request. // Handlers should not modify the provided Request.
type Handler interface { type Handler interface {
@ -100,7 +99,7 @@ func (t *timeoutHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *R
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
tw := &timeoutWriter{ tw := &timeoutWriter{
wc: &contextWriter{ wr: &contextWriter{
ctx: ctx, ctx: ctx,
cancel: cancel, cancel: cancel,
done: ctx.Done(), done: ctx.Done(),
@ -124,7 +123,7 @@ func (t *timeoutHandler) ServeGemini(ctx context.Context, w ResponseWriter, r *R
} }
type timeoutWriter struct { type timeoutWriter struct {
wc io.WriteCloser wr io.Writer
status Status status Status
meta string meta string
mediatype string mediatype string
@ -139,7 +138,7 @@ func (w *timeoutWriter) Write(b []byte) (int, error) {
if !w.wroteHeader { if !w.wroteHeader {
w.WriteHeader(StatusSuccess, w.mediatype) w.WriteHeader(StatusSuccess, w.mediatype)
} }
return w.wc.Write(b) return w.wr.Write(b)
} }
func (w *timeoutWriter) WriteHeader(status Status, meta string) { 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 { func (w *timeoutWriter) Flush() error {
return nil return nil
} }
func (w *timeoutWriter) Close() error {
return w.wc.Close()
}

View File

@ -147,10 +147,6 @@ type ResponseWriter interface {
// Flush sends any buffered data to the client. // Flush sends any buffered data to the client.
Flush() error Flush() error
// Close closes the connection.
// Any blocked Write operations will be unblocked and return errors.
Close() error
} }
type responseWriter struct { type responseWriter struct {
@ -161,10 +157,9 @@ type responseWriter struct {
bodyAllowed bool bodyAllowed bool
} }
func newResponseWriter(w io.WriteCloser) *responseWriter { func newResponseWriter(w io.Writer) *responseWriter {
return &responseWriter{ return &responseWriter{
bw: bufio.NewWriter(w), bw: bufio.NewWriter(w),
cl: w,
} }
} }
@ -210,7 +205,3 @@ func (w *responseWriter) Flush() error {
// Write errors from WriteHeader will be returned here. // Write errors from WriteHeader will be returned here.
return w.bw.Flush() return w.bw.Flush()
} }
func (w *responseWriter) Close() error {
return w.cl.Close()
}