Skip to content

Commit 8407a4f

Browse files
committed
Remove cors signature, use global middleware to handle preflight request
1 parent 33c7df6 commit 8407a4f

File tree

3 files changed

+0
-32
lines changed

3 files changed

+0
-32
lines changed

fasthttp.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ type fastHTTPRouter struct {
3232
fileServer fasthttp.RequestHandler
3333
notFound fasthttp.RequestHandler
3434
notAllowed fasthttp.RequestHandler
35-
cors fasthttp.RequestHandler
3635
handler fasthttp.RequestHandler
3736
middlewareCounter uint
3837
}
@@ -122,10 +121,6 @@ func (r *fastHTTPRouter) Compile() {
122121
}
123122
}
124123

125-
func (r *fastHTTPRouter) CORS(cors fasthttp.RequestHandler) {
126-
r.cors = cors
127-
}
128-
129124
func (r *fastHTTPRouter) NotFound(notFound fasthttp.RequestHandler) {
130125
r.notFound = notFound
131126
}
@@ -208,7 +203,6 @@ func (r *fastHTTPRouter) serveHTTP(ctx *fasthttp.RequestCtx) {
208203
ctx.Response.Header.Set("Allow", allow)
209204

210205
if method == fasthttp.MethodOptions {
211-
r.serveCors(ctx)
212206
return
213207
}
214208

@@ -221,12 +215,6 @@ func (r *fastHTTPRouter) serveHTTP(ctx *fasthttp.RequestCtx) {
221215
r.serveNotFound(ctx)
222216
}
223217

224-
func (r *fastHTTPRouter) serveCors(ctx *fasthttp.RequestCtx) {
225-
if r.cors != nil {
226-
r.cors(ctx)
227-
}
228-
}
229-
230218
func (r *fastHTTPRouter) serveNotFound(ctx *fasthttp.RequestCtx) {
231219
if r.notFound != nil {
232220
r.notFound(ctx)

nethttp.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type router struct {
3131
fileServer http.Handler
3232
notFound http.Handler
3333
notAllowed http.Handler
34-
cors http.Handler
3534
handler http.Handler
3635
middlewareCounter uint
3736
}
@@ -119,10 +118,6 @@ func (r *router) Compile() {
119118
}
120119
}
121120

122-
func (r *router) CORS(cors http.Handler) {
123-
r.cors = cors
124-
}
125-
126121
func (r *router) NotFound(notFound http.Handler) {
127122
r.notFound = notFound
128123
}
@@ -207,7 +202,6 @@ func (r *router) serveHTTP(w http.ResponseWriter, req *http.Request) {
207202
w.Header().Set("Allow", allow)
208203

209204
if req.Method == http.MethodOptions {
210-
r.serveCors(w, req)
211205
return
212206
}
213207

@@ -220,12 +214,6 @@ func (r *router) serveHTTP(w http.ResponseWriter, req *http.Request) {
220214
r.serveNotFound(w, req)
221215
}
222216

223-
func (r *router) serveCors(w http.ResponseWriter, req *http.Request) {
224-
if r.cors != nil {
225-
r.cors.ServeHTTP(w, req)
226-
}
227-
}
228-
229217
func (r *router) serveNotFound(w http.ResponseWriter, req *http.Request) {
230218
if r.notFound != nil {
231219
r.notFound.ServeHTTP(w, req)

router.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ type Router interface {
8282
// NotFound replies to the request with the
8383
// 405 Error code
8484
NotAllowed(http.Handler)
85-
86-
// CORS handler replies to request with cors header and handles preflight request
87-
// it is enhancement to improve middleware usability instead of wrapping every handler
88-
CORS(http.Handler)
8985
}
9086

9187
// FastHTTPRouter is a fasthttp micro framework, HTTP request router, multiplexer, mux
@@ -158,8 +154,4 @@ type FastHTTPRouter interface {
158154
// NotFound replies to the request with the
159155
// 405 Error code
160156
NotAllowed(fasthttp.RequestHandler)
161-
162-
// CORS handler replies to request with cors header and handles preflight request
163-
// it is enhancement to improve middleware usability instead of wrapping every handler
164-
CORS(fasthttp.RequestHandler)
165157
}

0 commit comments

Comments
 (0)