Skip to content

Commit

Permalink
feat: Add CORS support. (#232)
Browse files Browse the repository at this point in the history
This allows for connections from browser SDKs. Without CORS support
cross-origin requests will be blocked by the test harness.
  • Loading branch information
kinyoklion authored Sep 13, 2024
1 parent 3a227b8 commit 29364a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion framework/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,15 @@ func startServer(port int, handler http.Handler) error {
server := &http.Server{
Addr: fmt.Sprintf(":%d", port),
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "HEAD" {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "*")

if r.Method == http.MethodOptions || r.Method == http.MethodHead {
w.WriteHeader(200)
return
}

handler.ServeHTTP(w, r)
}),
ReadHeaderTimeout: 10 * time.Second, // arbitrary but non-infinite timeout to avoid Slowloris Attack
Expand Down

0 comments on commit 29364a8

Please sign in to comment.