diff options
| author | Shulhan <ms@kilabit.info> | 2019-03-15 21:39:04 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-03-17 02:12:43 +0700 |
| commit | d4a58da2becbb4ae46d2bbe57aa8bc2c99a0845e (patch) | |
| tree | 371557ee3e3f3e5bbb4c06bed3807d11f5303e89 /lib/websocket | |
| parent | 031ceb61f9a5a206a63160e78b8df80383d10b6b (diff) | |
| download | pakakeh.go-d4a58da2becbb4ae46d2bbe57aa8bc2c99a0845e.tar.xz | |
websocket: remove parameter randomMask from Frame.Pack
The decision to randomize mask is now based on whether the maskKey length
is equal to 4 or not. If its 4 the maskKey will not be randomized.
Diffstat (limited to 'lib/websocket')
| -rw-r--r-- | lib/websocket/client_test.go | 4 | ||||
| -rw-r--r-- | lib/websocket/frame.go | 9 | ||||
| -rw-r--r-- | lib/websocket/frame_test.go | 2 | ||||
| -rw-r--r-- | lib/websocket/server.go | 2 |
4 files changed, 8 insertions, 9 deletions
diff --git a/lib/websocket/client_test.go b/lib/websocket/client_test.go index 2d80dfc7..ee73c8fc 100644 --- a/lib/websocket/client_test.go +++ b/lib/websocket/client_test.go @@ -419,7 +419,7 @@ func TestClientFragmentation(t *testing.T) { wg.Add(1) for x := 0; x < len(c.frames); x++ { - req := c.frames[x].Pack(true) + req := c.frames[x].Pack() err := testClient.send(req) if err != nil { @@ -500,7 +500,7 @@ func TestClientFragmentation2(t *testing.T) { wg.Add(2) for x := 0; x < len(frames); x++ { - req := frames[x].Pack(true) + req := frames[x].Pack() err := testClient.send(req) if err != nil { diff --git a/lib/websocket/frame.go b/lib/websocket/frame.go index 9bc4887a..1b9c8690 100644 --- a/lib/websocket/frame.go +++ b/lib/websocket/frame.go @@ -181,7 +181,7 @@ func NewFrame(opcode Opcode, isMasked bool, payload []byte) []byte { if isMasked { f.masked = frameIsMasked } - return f.Pack(isMasked) + return f.Pack() } // @@ -203,13 +203,12 @@ func (f *Frame) Opcode() Opcode { // // Frame payload len will be set based on length of payload. // -// Frame maskKey will be set randomly only if masked is set and randomMask -// parameter is true. +// Frame maskKey will be set randomly only if its is empty. // // A server MUST NOT mask any frames that it sends to the client. // (RFC 6455 5.1-P27). // -func (f *Frame) Pack(randomMask bool) (out []byte) { +func (f *Frame) Pack() (out []byte) { headerSize := uint64(2) payloadSize := uint64(len(f.payload)) @@ -249,7 +248,7 @@ func (f *Frame) Pack(randomMask bool) (out []byte) { } if f.masked == frameIsMasked { - if randomMask { + if len(f.maskKey) != 4 { f.maskKey = make([]byte, 4) binary.LittleEndian.PutUint32(f.maskKey, rand.Uint32()) } diff --git a/lib/websocket/frame_test.go b/lib/websocket/frame_test.go index 4cca0beb..e70f8813 100644 --- a/lib/websocket/frame_test.go +++ b/lib/websocket/frame_test.go @@ -335,7 +335,7 @@ func TestFramePack(t *testing.T) { for _, c := range cases { t.Log(c.desc) - got := c.f.Pack(false) + got := c.f.Pack() test.Assert(t, "", c.exp, got, true) } diff --git a/lib/websocket/server.go b/lib/websocket/server.go index 7ed477fa..e20fb1dc 100644 --- a/lib/websocket/server.go +++ b/lib/websocket/server.go @@ -617,7 +617,7 @@ func (serv *Server) handlePing(conn int, req *Frame) { req.opcode = OpcodePong req.masked = 0 - res := req.Pack(false) + res := req.Pack() err := Send(conn, res) if err != nil { |
