response: Add Close method
This commit is contained in:
parent
311233a012
commit
ae3fc2fc73
18
response.go
18
response.go
@ -204,23 +204,29 @@ 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 Read or Write operations will be unblocked and return errors.
|
||||||
|
Close() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type responseWriter struct {
|
type responseWriter struct {
|
||||||
b *bufio.Writer
|
b *bufio.Writer
|
||||||
|
closer io.Closer
|
||||||
mediatype string
|
mediatype string
|
||||||
wroteHeader bool
|
wroteHeader bool
|
||||||
bodyAllowed bool
|
bodyAllowed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewResponseWriter returns a ResponseWriter that uses the provided io.Writer.
|
// NewResponseWriter returns a ResponseWriter that uses the provided io.Writer.
|
||||||
func NewResponseWriter(w io.Writer) ResponseWriter {
|
func NewResponseWriter(wc io.WriteCloser) ResponseWriter {
|
||||||
return newResponseWriter(w)
|
return newResponseWriter(wc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newResponseWriter(w io.Writer) *responseWriter {
|
func newResponseWriter(wc io.WriteCloser) *responseWriter {
|
||||||
return &responseWriter{
|
return &responseWriter{
|
||||||
b: bufio.NewWriter(w),
|
b: bufio.NewWriter(wc),
|
||||||
|
closer: wc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,3 +272,7 @@ func (w *responseWriter) Flush() error {
|
|||||||
// Write errors from writeHeader will be returned here.
|
// Write errors from writeHeader will be returned here.
|
||||||
return w.b.Flush()
|
return w.b.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *responseWriter) Close() error {
|
||||||
|
return w.closer.Close()
|
||||||
|
}
|
||||||
|
@ -102,3 +102,7 @@ func (w *timeoutWriter) writeHeaderLocked(status Status, meta string) {
|
|||||||
func (w *timeoutWriter) Flush() error {
|
func (w *timeoutWriter) Flush() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *timeoutWriter) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user