mirror of
https://github.com/openfaas/faas.git
synced 2025-06-24 15:53:26 +00:00
Refactoring: variable names, adding tests and http constants
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
@ -2,12 +2,13 @@ package handlers
|
||||
|
||||
import "net/http"
|
||||
|
||||
type CorsHandler struct {
|
||||
// CORSHandler set custom CORS instructions for the store.
|
||||
type CORSHandler struct {
|
||||
Upstream *http.Handler
|
||||
AllowedHost string
|
||||
}
|
||||
|
||||
func (c CorsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
func (c CORSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// https://raw.githubusercontent.com/openfaas/store/master/store.json
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET")
|
||||
@ -16,8 +17,9 @@ func (c CorsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
(*c.Upstream).ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
// DecorateWithCORS decorate a handler with CORS-injecting middleware
|
||||
func DecorateWithCORS(upstream http.Handler, allowedHost string) http.Handler {
|
||||
return CorsHandler{
|
||||
return CORSHandler{
|
||||
Upstream: &upstream,
|
||||
AllowedHost: allowedHost,
|
||||
}
|
||||
|
Reference in New Issue
Block a user