GoogleContainerTools/skaffold · error
creating http request: %w
Error message
creating http request: %w
What it means
Download issues an HTTP GET via util.Download. This error means http.NewRequest failed to construct the request itself — almost always because the URL is malformed (no scheme, invalid characters, bad host). The URL parse error is wrapped.
Source
Thrown at pkg/skaffold/util/http.go:31
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"fmt"
"io"
"net/http"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/version"
)
func Download(url string) ([]byte, error) {
client := http.Client{}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, fmt.Errorf("creating http request: %w", err)
}
req.Header.Set("User-Agent", version.UserAgentWithClient())
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("http %d, error %q", resp.StatusCode, resp.Status)
}
return io.ReadAll(resp.Body)
}
View on GitHub (pinned to a1189de023)
Solutions
- Print/inspect the URL passed to Download; validate it has scheme://host format.
- Trim whitespace/quotes from config-provided URLs before use (strings.TrimSpace).
- Escape path segments with url.PathEscape when interpolating user data.
- Reject empty URLs early with an explicit validation check.
Example fix
// before
url := fmt.Sprintf("%s/%s", base, name) // base may be "example.com/x" without scheme
b, err := util.Download(url)
// after
u, err := nurl.Parse(strings.TrimSpace(base))
if err != nil || u.Scheme == "" {
return nil, fmt.Errorf("invalid download URL: %q", base)
}
b, err := util.Download(u.String()) Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(rawURL)
if err != nil {
return fmt.Errorf("invalid URL %q: %w", rawURL, err)
}
if u.Scheme != "http" && u.Scheme != "https" || u.Host == "" {
return fmt.Errorf("URL must be absolute with host: %q", rawURL)
} Type guard
func isDownloadableURL(s string) bool {
u, err := url.Parse(strings.TrimSpace(s))
return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Host != ""
} Try / catch
b, err := util.Download(url)
if err != nil && strings.Contains(err.Error(), "creating http request") {
return fmt.Errorf("malformed download URL %q: %w", url, err)
} Prevention
- Always construct URLs with url.Parse/url.PathEscape, never raw string concat of user input
- Trim whitespace and quotes from URLs read from config or env
- Assert scheme and host presence before downloading
When it happens
Trigger: http.NewRequest("GET", url, nil) errors: url passed to Download is empty, missing scheme ('storage.googleapis.com/...' without https://), contains spaces or invalid control characters, or is otherwise rejected by net/url parsing.
Common situations: Building URLs by string concatenation with unescaped user input (image names, ports, endpoints) e.g. in ReadConfiguration fetching remote configs; environment-provided endpoint strings with typos; URLs read from config with surrounding whitespace or quotes.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- one platform returned an non-success response: %d
- %s is not a valid URL
- failed to download manifest from %s, err : %w
- starting HTTP server: %w
- getting latest version info from GCS: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/c6097517fe85c4a6.
Report an issue: GitHub.