| Age | Commit message (Collapse) | Author |
|
Go 1.22 now support for-range on numeric value.
|
|
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.
|
|
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
|
|
|
|
Adding prefix provide better way to locate and debug the error in the
future.
|
|
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.
|
|
During testing the Client we use the un-exported method send,
while the test cases itself may close the connection and we did not
guard it.
|
|
We only do lock on exported methods, but when doing testing we call
the send method without lock which cause read and write on Client.conn
at the same time.
|
|
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.
|
|
|
|
In the test cases we send two unmasked frames. Since the client
to server must be masked, but in this test we did not mask it,
when the server received first frame the connection may get closed
before we can send the second unmasked frame.
To detect this, we check if the error from send() is "broken pipe"
or not. If its true then test case stopped.
|
|
The following error thrown when running on Github Action using
Ubuntu-latest and Go 1.16.3,
client_test.go:472: write tcp 127.0.0.1:34460->127.0.0.1:9001:
write: connection reset by peer
This may be caused by using the same client connection on all test
cases.
We try to fix this by creating new client on each test cases.
|
|
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.
|
|
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 Close method send the control CLOSE frame to server and wait for
the CLOSE response.
This changes unexport the SendClose method.
|
|
|
|
In Go tip, the format of error on empty URL is `parse ""`
(with double quote), while in Go 1.13.4 there is no double quote on
error message.
|
|
|
|
|
|
|
|
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.
|
|
The Frame Pack method is only used internally, implementor should use
NewFrameXxx functions.
|
|
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.
|
|
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.
|
|
Some of the methods in ClientManager and Frames should be only accessed
by internal server, not by implementor.
|
|
The handler is called HandlerRsvControl that can be set before running
the server. Default HandlerRsvControl is nil.
Since the handler expect Frame as parameter, we need to adjust and add
two methods to access Frame's internal fields and methods; which is
exporting NewFrame function and Frame.Pack method, and adding method
Opcode() and Payload() to access Frame's opcode and payload.
|
|
|
|
This is to enable single client to be used on multiple routines.
|
|
|
|
Also, make sure we close the client connection from unit test.
|
|
The test require to add a new handler on server to check received control
PONG frame from 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
|
|
When server received unmasked frame or CLOSE control frame, the client
connection will be closed. To prevent the connection to be added back
to epoll we add a flag to indicate that connection will be closed.
|
|
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.
|
|
The method Pack on single frame is not usable in the point of view of
implementor, since we prefer NewFrameXxx to create frame by operation code.
|
|
function Concat in package bytes is more flexible, allow two or more slice
of byte in parameters.
|
|
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.
|
|
This changes introduced new parameters isMasked and close code status to
function NewFrameClose; and isMasked to function NewFramePing and
NewFramePong.
This commit also introduce new type for status code: CloseCode.
|
|
Most of the constants should not be used directly, as we prefer user to
use the functions or methods based access.
|
|
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.
|
|
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.
|
|
|
|
|
|
|
|
|