| Age | Commit message (Collapse) | Author |
|
The "nolint" tag is used to ignore lines from being processed by
golangci-lint.
Since we are not using golangci-lint anymore, now and in the
future, those lines can be removed.
|
|
For HTTP server that use TLS, set the minimum TLS version and
ReadHeaderTimeout to mitigate slowloris attack.
For HTTP client or server that parameterize the use of InsecureSkipVerify,
annotate the line with "nolint:gosec" to allow the code pass the check.
Library that still use sha1, in example in DKIM and TOTP, skip the
warnings by annotating the line with "nolint:gosec".
A pointer variable now allocated their address before assigning its
value.
Any error that returned now wrapped using "%w".
Also, replace error checking using [errors.Is] or [errors.As] instead of
using equal or not-equal operators.
In "lib/http", replace any usage of "math/rand" with "crypto/rand".
Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec"
since its false positive, the issue has been fixed in Go >= 1.17.7.
Any switch case that does not cover the rest of the possible values now
handled by adding the cases or by replacing the "default" case with
the rest of values.
|
|
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.
|
|
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
|
|
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.
|
|
This fix some linter warnings on dummy methods and handlers.
|
|
|
|
Adding prefix provide better way to locate and debug the error in the
future.
|
|
If the HTTP handshake response contains trailing frame, handle it
directly.
If the frame is invalid or control close operation, call Quit directly
to trigger the HandleQuit if its defined by user.
|
|
Using global debug value for all packages turns out is not a good
idea.
|
|
When calling Close, we initialize the internal channel gracefulClose
so the client can check the close response from server on another
goroutine serve() and signal back to Close to continue the closing
process.
This channel is never closed and nil-ed again after Close which
may cause resource leaks.
While at it, use sendClose to minimize duplicate code.
|
|
Both of those functions actually call send control CLOSE frame and not
exported.
So, instead of duplicating it, we replace it with sendClose.
|
|
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.
|
|
|
|
|
|
Replace assignment from using ":=" to use variable declaration with
type.
Rationale: clarity and minimize duplicate temporary variables with the
same type.
|
|
Changes,
* Client: from 176 to 144 (-32 bytes)
* ClientManager: from 64 to 40 (-24 bytes)
* Request: from 88 to 72 (-16 bytes)
* Response: from 40 to 24 (-16 bytes)
* route: from 48 to 32 (-16 bytes)
* Server: from 72 to 64 (-8 bytes)
* ServerOptions: from 104 to 96 (s-8 bytes)
Plus other structs in the tests.
|
|
|
|
The handleClose is a function that will be called when client receive
control CLOSE frame from server. Default handle is to response
with control CLOSE frame with the same payload.
This field is not exported, and only defined to allow testing.
|
|
If user set TLSConfig but the Endpoint is not start with "https" or "wss",
client open() method may return an error "Connect: tls: first record does
not look like a TLS handshake".
This commit fix inconsistencies between TLSConfig and Endpoint scheme.
|
|
|
|
|
|
Previously, we only check for "wss" scheme to initialize the TLS
configuration. At some point, user may have one single address to
connect to HTTP and WebSocket server on the same domain, which require
two addresses on their side.
This commit relaxing the Endpoint rule when parsing WebSocket URI.
Scheme "https" will be considered as "wss" or secure connection with
TLS.
|
|
|
|
The send interval can be set in Client.PingInterval. The minimum
and default value is 10 seconds.
|
|
The Close method send the control CLOSE frame to server and wait for
the CLOSE response.
This changes unexport the SendClose method.
|
|
This change will allow the client to use client certificate when
connecting to WebSocket server with self-signed certificate.
|
|
|
|
|
|
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.
|
|
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).
|
|
Use "fmt" package when printing debugging information, and "log" package
when printing error.
|
|
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.
|
|
Empty packet may indicated that server has closed the connection
abnormally and we need to close the socket clearly.
|
|
Also, check if the Endpoint URL contains query parameter before appending
the "?" to handshake request path.
|
|
The handler is called HandleQuit and can be used to clean resource or
reconnect to server. Default is nil.
|
|
Since the client receive is now unexported, handled internally, and
handler are centralized, there is no need to lock when doing write and
read on socket anymore.
The lock is still required when closing the socket, to prevent multiple
routines call Quit at the same time.
|
|
Since handler are created before creating a client and a handler may
send a response to server after receiving a message from server, we pass
the current client to handler as parameter.
|
|
This is to minimize duplicate code on client and server.
|
|
Previously, we use two function to unpack frame: frameUnpack and
continueUnpack, both of this functions actually use the same logic.
This commit merge both functions into Frame's unpack() and which also
make handleChopped() to be unused on both server and client.
|
|
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.
|
|
The opcode type is required to create new frame and to get the opcode in
continous frames.
|
|
Since bytes.Buffer only used once, on client handshake, there is no need
to keep it on Client.
|
|
This is to enable single client to be used on multiple routines.
|
|
|
|
Also, make sure we close the client connection from unit test.
|
|
This is to minimize duplicate code on client.
|
|
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.
|
|
Changes caused by test:
* handlePing become the internal field of client instead of method, so
it can be replaced during test
* add internal context ctxKeyFrame to save the expected frame in handler
|
|
This will make sure no routine is leaked if client want to reconnect again.
|