Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ukorvl
Copy link
Member

@ukorvl ukorvl commented Feb 5, 2025

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:

Updates to tests and client code:

@@ -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):]
Copy link
Contributor

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

Copy link
Contributor

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

Comment on lines 699 to 703
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")
})
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
niljs Related to niljs client library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants