Skip to content

Commit c8f5418

Browse files
authored
Merge pull request netlify#7 from netlify/fix-double-cors
Remove CORS headers from GitHub
2 parents 2a02177 + 962743d commit c8f5418

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

api/github.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ var allowedRegexp = regexp.MustCompile("^/github/(git|contents|pulls|branches)/"
1818

1919
func NewGitHubGateway() *GitHubGateway {
2020
return &GitHubGateway{
21-
proxy: &httputil.ReverseProxy{Director: director},
21+
proxy: &httputil.ReverseProxy{
22+
Director: director,
23+
Transport: &GitHubTransport{},
24+
},
2225
}
2326
}
2427

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

107110
return errors.New("Access to endpoint not allowed: your role doesn't allow access")
108111
}
112+
113+
type GitHubTransport struct{}
114+
115+
func (t *GitHubTransport) RoundTrip(r *http.Request) (*http.Response, error) {
116+
resp, err := http.DefaultTransport.RoundTrip(r)
117+
if err == nil {
118+
// remove CORS headers from GitHub and use our own
119+
resp.Header.Del("Access-Control-Allow-Origin")
120+
}
121+
return resp, err
122+
}

0 commit comments

Comments
 (0)