Skip to content

Commit 93d5271

Browse files
authored
Validate baseURL (#13)
1 parent 8ce5418 commit 93d5271

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

client/client.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,26 @@ type Client struct {
3939
HTTPClient *http.Client
4040
}
4141

42+
const defaultBaseURL = "https://build.sylabs.io"
43+
4244
// NewClient sets up a new build service client with the specified base URL and auth token.
4345
func NewClient(cfg *Config) (c *Client, err error) {
4446
if cfg == nil {
4547
cfg = DefaultConfig
4648
}
4749

4850
// Determine base URL
49-
bu := "https://build.sylabs.io"
51+
bu := defaultBaseURL
5052
if cfg.BaseURL != "" {
5153
bu = cfg.BaseURL
5254
}
5355
baseURL, err := url.Parse(bu)
5456
if err != nil {
5557
return nil, err
5658
}
59+
if baseURL.Scheme != "http" && baseURL.Scheme != "https" {
60+
return nil, fmt.Errorf("unsupported protocol scheme %q", baseURL.Scheme)
61+
}
5762

5863
c = &Client{
5964
BaseURL: baseURL,

0 commit comments

Comments
 (0)