Skip to content

Commit

Permalink
http: strip trailing slash from "BasePath"
Browse files Browse the repository at this point in the history
The generated Swagger http clients require a URL to which an method's
endpoint path is appended.  This is a problem if this base path has a
trailing slash since the endpoint paths begin with a slash.
The result is that kwild's server will report 404 not found, while kgw
would try to clean the path but redirect with GET even for POST.

This change fixes our http client constructors to trim trailing slashes
from the base URL.
  • Loading branch information
jchappelow authored and Yaiba committed Apr 9, 2024
1 parent 1744789 commit d6820ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion core/rpc/client/function/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"net/http"
"net/url"
"strings"

"github.com/kwilteam/kwil-db/core/crypto/auth"
httpFunction "github.com/kwilteam/kwil-db/core/rpc/http/function"
Expand All @@ -32,7 +33,7 @@ func NewClient(target *url.URL, opts ...ClientOption) *Client {

cfg := httpFunction.NewConfiguration()
cfg.HTTPClient = clientOpts.client
cfg.BasePath = target.String()
cfg.BasePath = strings.TrimRight(target.String(), "/")
cfg.Host = target.Host
cfg.Scheme = target.Scheme

Expand Down
2 changes: 1 addition & 1 deletion core/rpc/client/user/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewClient(target *url.URL, opts ...ClientOption) *Client {

cfg := httpTx.NewConfiguration()
cfg.HTTPClient = clientOpts.client
cfg.BasePath = target.String()
cfg.BasePath = strings.TrimRight(target.String(), "/")
cfg.Host = target.Host
cfg.Scheme = target.Scheme

Expand Down

0 comments on commit d6820ac

Please # to comment.