Conversation
test/README.md
Outdated
|
|
||
| ## Usage | ||
| 1. Run `cors_test_server.go` with `go run test/cors_test_server.go`. | ||
| 2. Open `http://localhost:8080` in your browser. |
There was a problem hiding this comment.
go run test/servefile.go
Also when hitting this url for the first time it gives you a full listing of the repo. The correct url is http://localhost:8085/test/cors_test.html
New functionality for router to add headers for CORS sites New config to specify allowed sites Small test server and script for testing ASG-5216
FritzOnFire
left a comment
There was a problem hiding this comment.
A whole bunch of small changes, but it should be good to merge after them.
There was a problem hiding this comment.
This feels like fluff, but please move this file one level deeper in case we need to use this folder for other more involved testing setups
New Dir: test/cors.
But then we can probably rename the file to test.html, as it would be obvious what the file is used for.
test/README.md
Outdated
There was a problem hiding this comment.
Same fluff comment as on the other file
test/README.md
Outdated
|
|
||
| ## Files | ||
|
|
||
| ### cors_test_server.go |
There was a problem hiding this comment.
| ### cors_test_server.go | |
| ### serverfile.go |
test/README.md
Outdated
| ## Files | ||
|
|
||
| ### cors_test_server.go | ||
| A minimal Go HTTP server that serves the `cors_test.html` file on `http://localhost:8080`. This allows you to easily load the test page in your browser. |
There was a problem hiding this comment.
| A minimal Go HTTP server that serves the `cors_test.html` file on `http://localhost:8080`. This allows you to easily load the test page in your browser. | |
| A minimal Go HTTP server that serves the `test.html` file on `http://localhost:8080`. This allows you to easily load the test page in your browser. |
test/README.md
Outdated
| ### cors_test_server.go | ||
| A minimal Go HTTP server that serves the `cors_test.html` file on `http://localhost:8080`. This allows you to easily load the test page in your browser. | ||
|
|
||
| ### cors_test.html |
There was a problem hiding this comment.
| ### cors_test.html | |
| ### test.html |
| // Set the Access-Control-Allow-Origin header, based on allow-list | ||
| s.errorLog.Infof("Forwarding from \"%v\"", req.Header.Get("Origin")) | ||
| _, ok := s.configHttp.Origins[req.Header.Get("Origin")] | ||
| if ok { | ||
| w.Header().Set("Access-Control-Allow-Origin", req.Header.Get("Origin")) | ||
| w.Header().Set("Access-Control-Allow-Credentials", "true") | ||
|
|
||
| // Handle preflight OPTIONS requests | ||
| if req.Method == "OPTIONS" { | ||
| w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") | ||
| w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") | ||
| w.WriteHeader(http.StatusOK) | ||
| return | ||
| } | ||
| } |
There was a problem hiding this comment.
Just to minimize the impact on our standard config.
| // Set the Access-Control-Allow-Origin header, based on allow-list | |
| s.errorLog.Infof("Forwarding from \"%v\"", req.Header.Get("Origin")) | |
| _, ok := s.configHttp.Origins[req.Header.Get("Origin")] | |
| if ok { | |
| w.Header().Set("Access-Control-Allow-Origin", req.Header.Get("Origin")) | |
| w.Header().Set("Access-Control-Allow-Credentials", "true") | |
| // Handle preflight OPTIONS requests | |
| if req.Method == "OPTIONS" { | |
| w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") | |
| w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") | |
| w.WriteHeader(http.StatusOK) | |
| return | |
| } | |
| } | |
| if len(s.configHttp.Origins) > 0 { | |
| // Set the Access-Control-Allow-Origin header, based on allow-list | |
| og := req.Header.Get("Origin") | |
| s.errorLog.Infof("Forwarding from \"%v\"", og) | |
| if _, ok := s.configHttp.Origins[og]; ok { | |
| w.Header().Set("Access-Control-Allow-Origin", og) | |
| w.Header().Set("Access-Control-Allow-Credentials", "true") | |
| // Handle preflight OPTIONS requests | |
| if req.Method == "OPTIONS" { | |
| w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") | |
| w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") | |
| w.WriteHeader(http.StatusOK) | |
| return | |
| } | |
| } | |
| } |
Fixup CORS file server Fixup docs Move cors tests and resources to /test/cors
bosvos
left a comment
There was a problem hiding this comment.
I've made the other changes apart from the pointer one. @FritzOnFire
FritzOnFire
left a comment
There was a problem hiding this comment.
Just that extra if statement in server.go but then this is good to merge
Refs: ASG-5216