Skip to content

Commit

Permalink
Merge pull request netlify#7 from netlify/fix-double-cors
Browse files Browse the repository at this point in the history
Remove CORS headers from GitHub
  • Loading branch information
brycekahle authored Sep 18, 2017
2 parents 2a02177 + 962743d commit c8f5418
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion api/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ var allowedRegexp = regexp.MustCompile("^/github/(git|contents|pulls|branches)/"

func NewGitHubGateway() *GitHubGateway {
return &GitHubGateway{
proxy: &httputil.ReverseProxy{Director: director},
proxy: &httputil.ReverseProxy{
Director: director,
Transport: &GitHubTransport{},
},
}
}

Expand Down Expand Up @@ -106,3 +109,14 @@ func (gh *GitHubGateway) authenticate(w http.ResponseWriter, r *http.Request) er

return errors.New("Access to endpoint not allowed: your role doesn't allow access")
}

type GitHubTransport struct{}

func (t *GitHubTransport) RoundTrip(r *http.Request) (*http.Response, error) {
resp, err := http.DefaultTransport.RoundTrip(r)
if err == nil {
// remove CORS headers from GitHub and use our own
resp.Header.Del("Access-Control-Allow-Origin")
}
return resp, err
}

0 comments on commit c8f5418

Please sign in to comment.