Skip to content

Commit

Permalink
feat(writer): add support for SetWriteDeadline and SetReadDeadline
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Oct 8, 2024
1 parent 190fabd commit fc79abf
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,21 @@ func (r *recorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return nil, nil, ErrNotSupported()
}

// SetReadDeadline sets the deadline for reading the entire request, including the body. Reads from the request
// body after the deadline has been exceeded will return an error. A zero value means no deadline. Setting the read
// deadline after it has been exceeded will not extend it. If SetReadDeadline is not supported, it returns
// an error matching http.ErrNotSupported.
func (r *recorder) SetReadDeadline(deadline time.Time) error {
if w, ok := r.ResponseWriter.(interface{ SetReadDeadline(time.Time) error }); ok {
return w.SetReadDeadline(deadline)
}
return ErrNotSupported()
}

// SetWriteDeadline sets the deadline for writing the response. Writes to the response body after the deadline has
// been exceeded will not block, but may succeed if the data has been buffered. A zero value means no deadline.
// Setting the write deadline after it has been exceeded will not extend it. If SetWriteDeadline is not supported,
// it returns an error matching http.ErrNotSupported.
func (r *recorder) SetWriteDeadline(deadline time.Time) error {
if w, ok := r.ResponseWriter.(interface{ SetWriteDeadline(time.Time) error }); ok {
return w.SetWriteDeadline(deadline)
Expand Down

0 comments on commit fc79abf

Please sign in to comment.