mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
add Context.ResponseWriter.IsHijacked to report whether the underline conn is already hijacked and a lot of cleanup and minor ws stress test example improvements
Former-commit-id: 444d4f0718d5c6d7544834c5e44dafb872980238
This commit is contained in:
@@ -41,6 +41,9 @@ type ResponseWriter interface {
|
||||
// Here is the place which we can make the last checks or do a cleanup.
|
||||
EndResponse()
|
||||
|
||||
// IsHijacked reports whether this response writer's connection is hijacked.
|
||||
IsHijacked() bool
|
||||
|
||||
// Writef formats according to a format specifier and writes to the response.
|
||||
//
|
||||
// Returns the number of bytes written and any write error encountered.
|
||||
@@ -195,6 +198,15 @@ func (w *responseWriter) tryWriteHeader() {
|
||||
}
|
||||
}
|
||||
|
||||
// IsHijacked reports whether this response writer's connection is hijacked.
|
||||
func (w *responseWriter) IsHijacked() bool {
|
||||
// Note:
|
||||
// A zero-byte `ResponseWriter.Write` on a hijacked connection will
|
||||
// return `http.ErrHijacked` without any other side effects.
|
||||
_, err := w.ResponseWriter.Write(nil)
|
||||
return err == http.ErrHijacked
|
||||
}
|
||||
|
||||
// Write writes to the client
|
||||
// If WriteHeader has not yet been called, Write calls
|
||||
// WriteHeader(http.StatusOK) before writing the data. If the Header
|
||||
|
||||
Reference in New Issue
Block a user