aboutsummaryrefslogtreecommitdiff
path: root/lib/websocket/server_test.go
AgeCommit message (Collapse)Author
2026-01-03all: use SPDX license header formatShulhan
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.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2024-02-15all: set unused parameter to "_"Shulhan
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-07-01lib/websocket: handle concurrent upgrade using goroutineShulhan
The maxGoroutineUpgrader define maximum goroutines running at the same time to handle client upgrade. The new goroutine only dispatched when others are full, so it will run incrementally not all at once. Default to defServerMaxGoroutineUpgrader (128) if its not set.
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.
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
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.
2019-11-14websocket: update NewServer usage on testShulhan
2019-03-20websocket: use custom HTTP parser for clientShulhan
The problem with using the standard http.ReadResponse is that the received packet may contains WebSocket frame, not just HTTP response. This cause the initial frame lost, which may required by client (for example, as a response for authentication).
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-17websocket: rewrite client to use centralized handlerShulhan
Unlike HTTP client or other most commmon TCP oriented client, the WebSocket client is actually asynchronous or passive-active instead of synchronous. At any time client connection is open to server, client can receive a message broadcast from server. Case examples: if client send "A" to server, and expect that server response with "A+", server may send message "B" before sending "A+". Another case is when client connection is open, server may send "B" and "C" in any order without any request send by client previously. Due to this model, the way to handle response from server is centralized using handlers instead of using single send request-response.
2019-03-04websocket: refactoring client, add specific SendXxx methodsShulhan
The idea is to allow client to send message without worrying how to create frame manually. So, the new client provide the following methods: SendBin, SendClose, SendPing, SendPong, and SendText.
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.
2018-11-29all: fix warnings from lintersShulhan
2018-11-29all: fix warning from lintersShulhan
2018-07-06Add implementation of websocket server and client (RFC 6455)Shulhan