diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-22 21:33:10 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-22 21:34:16 +0700 |
| commit | 360cd7bdc721c2aa968e2f6888db1c7e36538ae2 (patch) | |
| tree | 08c6610214a4da1b54707231c235e81127deeae6 /lib/websocket | |
| parent | cdf43c8a97f6fbe7548aa45d3ce2680bdeb70e36 (diff) | |
| download | pakakeh.go-360cd7bdc721c2aa968e2f6888db1c7e36538ae2.tar.xz | |
lib/bytes: replace Copy and Concat with standard library
Since Go 1.20, the standard bytes package have the Copy function.
Since Go 1.22, the standard slices package have the Concat function.
Diffstat (limited to 'lib/websocket')
| -rw-r--r-- | lib/websocket/frame_test.go | 20 | ||||
| -rw-r--r-- | lib/websocket/frames_test.go | 16 | ||||
| -rw-r--r-- | lib/websocket/server.go | 10 |
3 files changed, 23 insertions, 23 deletions
diff --git a/lib/websocket/frame_test.go b/lib/websocket/frame_test.go index bab2b04c..b4b84181 100644 --- a/lib/websocket/frame_test.go +++ b/lib/websocket/frame_test.go @@ -1,13 +1,13 @@ -// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package websocket import ( + "slices" "testing" - libbytes "git.sr.ht/~shulhan/pakakeh.go/lib/bytes" "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) @@ -75,7 +75,7 @@ func TestNewFrameClose(t *testing.T) { opcode: OpcodeClose, closeCode: StatusBadRequest, masked: frameIsMasked, - payload: libbytes.Concat([]byte{0x03, 0xEA}, + payload: slices.Concat([]byte{0x03, 0xEA}, []byte("Hello!")), }, }, { @@ -86,7 +86,7 @@ func TestNewFrameClose(t *testing.T) { opcode: OpcodeClose, closeCode: StatusBadRequest, masked: frameIsMasked, - payload: libbytes.Concat([]byte{0x03, 0xEA}, + payload: slices.Concat([]byte{0x03, 0xEA}, _dummyPayload256[:123]), }, }} @@ -339,7 +339,7 @@ func TestFramePack(t *testing.T) { masked: 0, payload: _dummyPayload256, }, - exp: libbytes.Concat([]byte{0x82, 0x7E, 0x01, 0x00}, + exp: slices.Concat([]byte{0x82, 0x7E, 0x01, 0x00}, _dummyPayload256), }, { desc: `256 bytes binary message in a single masked frame`, @@ -350,7 +350,7 @@ func TestFramePack(t *testing.T) { payload: _dummyPayload256, maskKey: _testMaskKey, }, - exp: libbytes.Concat([]byte{ + exp: slices.Concat([]byte{ 0x82, 0xFE, 0x01, 0x00, _testMaskKey[0], _testMaskKey[1], _testMaskKey[2], @@ -364,7 +364,7 @@ func TestFramePack(t *testing.T) { masked: 0, payload: _dummyPayload65536, }, - exp: libbytes.Concat([]byte{ + exp: slices.Concat([]byte{ 0x82, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, }, _dummyPayload65536), @@ -378,7 +378,7 @@ func TestFramePack(t *testing.T) { maskKey: _testMaskKey, len: 65536, }, - exp: libbytes.Concat([]byte{ + exp: slices.Concat([]byte{ 0x82, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, _testMaskKey[0], _testMaskKey[1], _testMaskKey[2], diff --git a/lib/websocket/frames_test.go b/lib/websocket/frames_test.go index 5cd4a098..6753210d 100644 --- a/lib/websocket/frames_test.go +++ b/lib/websocket/frames_test.go @@ -1,13 +1,13 @@ -// Copyright 2019, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2019 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package websocket import ( + "slices" "testing" - libbytes "git.sr.ht/~shulhan/pakakeh.go/lib/bytes" "git.sr.ht/~shulhan/pakakeh.go/lib/test" ) @@ -114,7 +114,7 @@ func TestFrameUnpack(t *testing.T) { }, }, { desc: `256 bytes binary message in a single unmasked frame`, - in: libbytes.Concat([]byte{0x82, 0x7E, 0x01, 0x00}, + in: slices.Concat([]byte{0x82, 0x7E, 0x01, 0x00}, _dummyPayload256), exp: &Frame{ fin: frameIsFinished, @@ -126,7 +126,7 @@ func TestFrameUnpack(t *testing.T) { }, }, { desc: `256 bytes binary message in a single masked frame`, - in: libbytes.Concat([]byte{ + in: slices.Concat([]byte{ 0x82, 0xFE, 0x01, 0x00, _testMaskKey[0], _testMaskKey[1], _testMaskKey[2], _testMaskKey[3], @@ -142,7 +142,7 @@ func TestFrameUnpack(t *testing.T) { }, }, { desc: `65536 binary message in a single unmasked frame`, - in: libbytes.Concat([]byte{ + in: slices.Concat([]byte{ 0x82, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, }, _dummyPayload65536), @@ -156,7 +156,7 @@ func TestFrameUnpack(t *testing.T) { }, }, { desc: `65536 binary message in a single masked frame`, - in: libbytes.Concat([]byte{ + in: slices.Concat([]byte{ 0x82, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, _testMaskKey[0], _testMaskKey[1], _testMaskKey[2], diff --git a/lib/websocket/server.go b/lib/websocket/server.go index 37d39a7d..0a0a1200 100644 --- a/lib/websocket/server.go +++ b/lib/websocket/server.go @@ -1,10 +1,11 @@ -// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. +// SPDX-FileCopyrightText: 2018 M. Shulhan <ms@kilabit.info> +// +// SPDX-License-Identifier: BSD-3-Clause package websocket import ( + "bytes" "context" "encoding/json" "errors" @@ -19,7 +20,6 @@ import ( "golang.org/x/sys/unix" - libbytes "git.sr.ht/~shulhan/pakakeh.go/lib/bytes" libnet "git.sr.ht/~shulhan/pakakeh.go/lib/net" ) @@ -211,7 +211,7 @@ func (serv *Server) handleUpgrade(hs *Handshake) (ctx context.Context, key []byt goto out } - key = libbytes.Copy(hs.Key) + key = bytes.Clone(hs.Key) if serv.Options.HandleAuth != nil { ctx, err = serv.Options.HandleAuth(hs) } |
