@@ -17,8 +17,6 @@ import (
17
17
"github.com/coder/websocket/internal/util"
18
18
)
19
19
20
- var ErrMessageTooBig = errors .New ("websocket: message too big" )
21
-
22
20
// Reader reads from the connection until there is a WebSocket
23
21
// data message to be read. It will handle ping, pong and close frames as appropriate.
24
22
//
@@ -92,7 +90,8 @@ func (c *Conn) CloseRead(ctx context.Context) context.Context {
92
90
//
93
91
// By default, the connection has a message read limit of 32768 bytes.
94
92
//
95
- // When the limit is hit, the connection will be closed with StatusMessageTooBig.
93
+ // When the limit is hit, reads return an error wrapping ErrMessageTooBig and
94
+ // the connection is closed with StatusMessageTooBig.
96
95
//
97
96
// Set to -1 to disable.
98
97
func (c * Conn ) SetReadLimit (n int64 ) {
@@ -522,9 +521,9 @@ func (lr *limitReader) Read(p []byte) (int, error) {
522
521
}
523
522
524
523
if lr .n == 0 {
525
- err := fmt .Errorf ("%w: %d bytes" , ErrMessageTooBig , lr .limit .Load ())
526
- lr .c .writeError (StatusMessageTooBig , err )
527
- return 0 , err
524
+ reason := fmt .Errorf ("read limited at %d bytes" , lr .limit .Load ())
525
+ lr .c .writeError (StatusMessageTooBig , reason )
526
+ return 0 , fmt . Errorf ( "%w: %v" , ErrMessageTooBig , reason )
528
527
}
529
528
530
529
if int64 (len (p )) > lr .n {
0 commit comments