Fix recovered panic when websocket is mirrored
This commit is contained in:
parent
b113972bcf
commit
38508f9a9c
2 changed files with 64 additions and 3 deletions
|
@ -1,8 +1,10 @@
|
|||
package mirror
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
|
@ -75,7 +77,7 @@ func (m *Mirroring) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
|
||||
// AddMirror adds an httpHandler to mirror to.
|
||||
func (m *Mirroring) AddMirror(handler http.Handler, percent int) error {
|
||||
if percent < 0 || percent >= 100 {
|
||||
if percent < 0 || percent > 100 {
|
||||
return errors.New("percent must be between 0 and 100")
|
||||
}
|
||||
m.mirrorHandlers = append(m.mirrorHandlers, &mirrorHandler{Handler: handler, percent: percent})
|
||||
|
@ -84,6 +86,12 @@ func (m *Mirroring) AddMirror(handler http.Handler, percent int) error {
|
|||
|
||||
type blackholeResponseWriter struct{}
|
||||
|
||||
func (b blackholeResponseWriter) Flush() {}
|
||||
|
||||
func (b blackholeResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return nil, nil, errors.New("you can hijack connection on blackholeResponseWriter")
|
||||
}
|
||||
|
||||
func (b blackholeResponseWriter) Header() http.Header {
|
||||
return http.Header{}
|
||||
}
|
||||
|
@ -92,8 +100,7 @@ func (b blackholeResponseWriter) Write(bytes []byte) (int, error) {
|
|||
return len(bytes), nil
|
||||
}
|
||||
|
||||
func (b blackholeResponseWriter) WriteHeader(statusCode int) {
|
||||
}
|
||||
func (b blackholeResponseWriter) WriteHeader(statusCode int) {}
|
||||
|
||||
type contextStopPropagation struct {
|
||||
context.Context
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue