diff --git a/cors.go b/cors.go index 4bb22d8..32f12bd 100644 --- a/cors.go +++ b/cors.go @@ -26,9 +26,6 @@ import ( "os" "strconv" "strings" - - "github.com/rs/xhandler" - "golang.org/x/net/context" ) // Options is a configuration container to setup the CORS middleware. @@ -192,29 +189,6 @@ func (c *Cors) Handler(h http.Handler) http.Handler { }) } -// HandlerC is net/context aware handler -func (c *Cors) HandlerC(h xhandler.HandlerC) xhandler.HandlerC { - return xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) { - if r.Method == "OPTIONS" { - c.logf("Handler: Preflight request") - c.handlePreflight(w, r) - // Preflight requests are standalone and should stop the chain as some other - // middleware may not handle OPTIONS requests correctly. One typical example - // is authentication middleware ; OPTIONS requests won't carry authentication - // headers (see #1) - if c.optionPassthrough { - h.ServeHTTPC(ctx, w, r) - } else { - w.WriteHeader(http.StatusOK) - } - } else { - c.logf("Handler: Actual request") - c.handleActualRequest(w, r) - h.ServeHTTPC(ctx, w, r) - } - }) -} - // HandlerFunc provides Martini compatible handler func (c *Cors) HandlerFunc(w http.ResponseWriter, r *http.Request) { if r.Method == "OPTIONS" { diff --git a/examples/xhandler/server.go b/examples/xhandler/server.go deleted file mode 100644 index 649a1c7..0000000 --- a/examples/xhandler/server.go +++ /dev/null @@ -1,24 +0,0 @@ -package main - -import ( - "net/http" - - "github.com/rs/cors" - "github.com/rs/xhandler" - "golang.org/x/net/context" -) - -func main() { - c := xhandler.Chain{} - - // Use default options - c.UseC(cors.Default().HandlerC) - - mux := http.NewServeMux() - mux.Handle("/", c.Handler(xhandler.HandlerFuncC(func(ctx context.Context, w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.Write([]byte("{\"hello\": \"world\"}")) - }))) - - http.ListenAndServe(":8080", mux) -}