Skip to content

Commit

Permalink
fix no Host in URL when SetScheme invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 24, 2022
1 parent 3da9823 commit 9a27463
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ func parseRequestURL(c *Client, r *Request) error {
return err
}

if reqURL.Scheme == "" && len(c.scheme) > 0 { // set scheme if missing
reqURL, err = url.Parse(c.scheme + "://" + tempURL)
if err != nil {
return err
}
}

// If RawURL is relative path then added c.BaseURL into
// the request URL otherwise Request.URL will be used as-is
if !reqURL.IsAbs() {
Expand All @@ -408,14 +415,6 @@ func parseRequestURL(c *Client, r *Request) error {
}
}

if reqURL.Scheme == "" && len(c.scheme) > 0 {
reqURL.Scheme = c.scheme
reqURL, err = url.Parse(reqURL.String()) // prevent empty URL.Host
if err != nil {
return err
}
}

// Adding Query Param
query := make(url.Values)
for k, v := range c.QueryParams {
Expand Down

0 comments on commit 9a27463

Please sign in to comment.