Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea87744

Browse files
committed
netconn: Disable read limit on WebSocket
Closes#245
1 parent085d46c commitea87744

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

‎netconn.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ import (
3838
//
3939
// A received StatusNormalClosure or StatusGoingAway close frame will be translated to
4040
// io.EOF when reading.
41+
//
42+
// Furthermore, the ReadLimit is set to -1 to disable it.
4143
funcNetConn(ctx context.Context,c*Conn,msgTypeMessageType) net.Conn {
44+
c.SetReadLimit(-1)
45+
4246
nc:=&netConn{
4347
c:c,
4448
msgType:msgType,

‎read.go‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,16 @@ func (c *Conn) CloseRead(ctx context.Context) context.Context {
7474
// By default, the connection has a message read limit of 32768 bytes.
7575
//
7676
// When the limit is hit, the connection will be closed with StatusMessageTooBig.
77+
//
78+
// Set to -1 to disable.
7779
func (c*Conn)SetReadLimit(nint64) {
78-
// We add read one more byte than the limit in case
79-
// there is a fin frame that needs to be read.
80-
c.msgReader.limitReader.limit.Store(n+1)
80+
ifn>=0 {
81+
// We read one more byte than the limit in case
82+
// there is a fin frame that needs to be read.
83+
n++
84+
}
85+
86+
c.msgReader.limitReader.limit.Store(n)
8187
}
8288

8389
constdefaultReadLimit=32768
@@ -455,7 +461,11 @@ func (lr *limitReader) reset(r io.Reader) {
455461
}
456462

457463
func (lr*limitReader)Read(p []byte) (int,error) {
458-
iflr.n<=0 {
464+
iflr.n<0 {
465+
returnlr.r.Read(p)
466+
}
467+
468+
iflr.n==0 {
459469
err:=fmt.Errorf("read limited at %v bytes",lr.limit.Load())
460470
lr.c.writeError(StatusMessageTooBig,err)
461471
return0,err
@@ -466,6 +476,9 @@ func (lr *limitReader) Read(p []byte) (int, error) {
466476
}
467477
n,err:=lr.r.Read(p)
468478
lr.n-=int64(n)
479+
iflr.n<0 {
480+
lr.n=0
481+
}
469482
returnn,err
470483
}
471484

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp