Skip to content

Commit

Permalink
Fix pseudo git HTTP urls broken since 59c82659
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
  • Loading branch information
sylr committed Feb 5, 2022
1 parent c3c7013 commit 6756b3e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/loader/fileloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package loader

import (
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -298,10 +299,11 @@ func (fl *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
}

// Load returns the content of file at the given path,
// else an error. Relative paths are taken relative
// else an error. Relative paths are taken relative
// to the root.
func (fl *fileLoader) Load(path string) ([]byte, error) {
if u, err := url.Parse(path); err == nil && (u.Scheme == "http" || u.Scheme == "https") {

var hc *http.Client
if fl.http != nil {
hc = fl.http
Expand All @@ -314,6 +316,10 @@ func (fl *fileLoader) Load(path string) ([]byte, error) {
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
_, err := git.NewRepoSpecFromUrl(path)
if err == nil {
return nil, errors.New("URL is a git repository")
}
return nil, fmt.Errorf("%w: status code %d (%s)", ErrorHTTP, resp.StatusCode, http.StatusText(resp.StatusCode))
}
body, err := ioutil.ReadAll(resp.Body)
Expand Down

0 comments on commit 6756b3e

Please sign in to comment.