aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/websocket_test.go
AgeCommit message (Collapse)Author
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-06-29lib/websocket: add option to set read/write timeout on ServerShulhan
The ReadWriteTimeout define the maximum duration the server wait when receiving/sending packet from/to client before considering the connection as broken. Default read-write timeout is 30 seconds if not set. This changes affect the exported function Send and Recv by adding additional parameter timeout to both of them.
2022-10-10lib/websocket: fix possible data race on ClientShulhan
The Client have method send that check if the underlying connection (conn) has been closed or not. Since the conn can be closed anytime, for example server send to the control CLOSE frame: recv -> handleFrame -> handleClose -> Quit we need to guard the conn with Mutex before calling send to prevent data race.
2022-06-09lib/websocket: refactoring codeShulhan
Replace assignment from using ":=" to use variable declaration with type. Rationale: clarity and minimize duplicate temporary variables with the same type.
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2020-08-11websocket: reformat some filesShulhan
2020-08-11websocket: move the server handler to ServerOptionsShulhan
2020-08-11websocket: add server options to change the connect and status pathsShulhan
Previously, there is only one option for server, the port where it will listen. This changes add option to change the connect path (default to "/" previously) and new path and handler for retrieving server status.
2020-08-10websocket: add HTTP endpoint to check server health statusShulhan
Requesting "GET /health" on WebSocket server will return HTTP status code 204, which can be used for service health checking.
2020-06-06all: use default linter optionsShulhan
2020-01-23websocket: add delay after running test serverShulhan
This is to prevent the actual test running before server is ready, which cause the test sometimes fails.
2019-11-14websocket: update NewServer usage on testShulhan
2019-06-14all: fix nolint formatShulhan
The valid syntax to suppress linter warnings is "//nolint:<name>" with no space between comment and "nolint" and between ":". Also, we move the placement of nolint directive to the top of statements for multiple nolint in the same scope. While at it, fix and supress some linter warnings.
2019-03-17websocket: simplify client handshake process without handler and contextShulhan
User of library that want to create WebSocket client should only focus to the Endpoint and/or Headers when creating client. While at it, change handshake test to check for error instead of status code.
2019-03-11websocket: handle chopped frame with interjected control frameShulhan
Another possibility is fragmented frames with one of the frame is chopped and in the middle of it is a control FRAME. For example, C> Frame{fin:false opcode:TEXT len:1024 payload:512} C> payload:512 FRAME{fin:TRUE opcode:PING len:0} C> Frame{fin:true opcode:0 len:1024 payload:1024}
2019-03-10websocket: check for error when running test serverShulhan
2019-03-07websocket: set the _testUID type to uint64 to minimize type convertionShulhan
2019-03-07websocket: add unit test for client SendClose and QuitShulhan
Also, make sure we close the client connection from unit test.
2019-03-07websocket: remove client connection stateShulhan
Previously, client connection state is used to disallow send or receive if client is not connected to remote server. This check also can be done by checking for nil on connection field.
2019-03-06websocket: enhanced the log output on serverShulhan
Use the log package with prefix instead of fmt.Fprintln.
2019-03-06websocket: refactoring handling fragmentation on serverShulhan
The temporary storage for continuous frame is moved from server to ClientManager, to prevent data race when modifying it and to allow one central function to clear it (when client closed). Another changes is on server handle parameter on HandleText and HandleBin. Previously, we pass the frame to handler, now we pass the payload since that is the real message the client send.
2019-03-05websocket: rename UserSockets to ClientManagerShulhan
ClientManager manage all of active connection in server. The ClientManager is part of the Server now, instead of separated instance.
2019-03-05websocket: unexported the Frame fields Fin and MaskedShulhan
Continuing refactor, this commit unexport all fields in Frame to allow user focus working with method and packet, let the technical detail managed by library.
2019-03-04websocket: inline the "nolint: gochecknoglobals"Shulhan
This is for easily peek the global variables name when doing grep.
2019-03-04websocket: minimize global variables and unexport internal constantsShulhan
Most of the constants should not be used directly, as we prefer user to use the functions or methods based access.
2019-03-04websocket: simplify client APIsShulhan
The client API now contains only NewClient() to create and connect to remote server, Send() to send package to remote server, and Recv() to receive package from remote. All fields and methods that is directly related to client usage are unexported.
2019-03-01all: fix warnings from linterShulhan
Most of the warnings caused by update to linter which cause global variables declared with grouping "( ... )" and that has been suppressed, are become false-positive again.
2018-11-30all: fix and suppress linter warnings on long linesShulhan
2018-11-30all: minimize and suppress linter warnings for global variablesShulhan
2018-11-29all: fix warnings from lintersShulhan
2018-07-06Add implementation of websocket server and client (RFC 6455)Shulhan