-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add niljs/ prefix to niljs Client-Version header #193
base: main
Are you sure you want to change the base?
Conversation
78f01b2
to
d8191b4
Compare
d8191b4
to
7c33441
Compare
7c33441
to
49c9650
Compare
@@ -98,8 +98,9 @@ func (s *Server) validateRequest(r *http.Request) (int, error) { | |||
|
|||
// Niljs is supported by server | |||
header := r.Header.Get(nilJsVersionHeader) | |||
if header != "" { | |||
version, err := semver.NewVersion(header) | |||
parsedHeader := header[len(niljsClientVersionPrefix):] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check that header length is enough. Otherwise it's easy to crash server by invalid header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can use strings.HasPrefix
function
s.Run("Unsupported version", func() { | ||
client := rpc_client.NewClientWithDefaultHeaders(s.Endpoint, logger, map[string]string{"Client-Version": "0.0.1"}) | ||
client := rpc_client.NewClientWithDefaultHeaders(s.Endpoint, logger, map[string]string{"Client-Version": "niljs/0.0.1"}) | ||
_, err := client.ChainId(s.Context) | ||
s.Require().ErrorContains(err, "unexpected status code: 426: specified niljs version 0.0.1, minimum supported is") | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add new test that checks that "Client-Version": "abc"
is handled properly
This pull request introduces changes to include a version prefix in the
Client-Version
header. The most important changes include defining a new constant for the version prefix, updating the server to handle the prefixed version, and modifying tests and client code to use the new version format.Changes to version management:
nil/services/rpc/internal/http/connection.go
: Added a new constantniljsClientVersionPrefix
to define the version prefix.nil/services/rpc/internal/http/server.go
: IntroducedniljsClientVersionPrefixLength
andtrimmedMinSupportedNiljsVersion
to handle the prefixed version and updatedparsedMinSupportedNiljsVersion
to use the trimmed version.Updates to tests and client code:
nil/tests/basic/basic_test.go
: Updated test cases to use the newClient-Version
format with theniljs/
prefix.niljs/src/rpc/rpcClient.ts
: Modified thecreateRPCClient
function to include theniljs/
prefix in theClient-Version
header.