Skip to content

Commit

Permalink
Add cors headers to every response (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
altafan authored Sep 26, 2022
1 parent 84e3194 commit 87b0601
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pkg/torproxy/torproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func reverseProxy(redirects []*url.URL, lis net.Listener, dialer proxy.Dialer) e
http.HandleFunc(removeForUpstream+"/", func(w http.ResponseWriter, r *http.Request) {

// add cors headers
addCorsHeader(w, r)
addCorsHeader(w)

// prepare request removing useless headers
if err := prepareRequest(r); err != nil {
Expand All @@ -286,10 +286,7 @@ func withoutOnion(host string) string {
return strings.ReplaceAll(hostWithoutPort, ".onion", "")
}

func addCorsHeader(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodOptions {
return
}
func addCorsHeader(w http.ResponseWriter) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "*")
Expand Down

0 comments on commit 87b0601

Please sign in to comment.