forked from savsgio/atreugo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
included before handler to modify request context
- Loading branch information
1 parent
b984460
commit 2a916cd
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
diff --git a/atreugo.go b/atreugo.go | ||
index c81bce9..87dc2ce 100644 | ||
--- a/atreugo.go | ||
+++ b/atreugo.go | ||
@@ -121,6 +121,13 @@ func newFasthttpServer(cfg Config) *fasthttp.Server { | ||
func (s *Atreugo) handler() fasthttp.RequestHandler { | ||
handler := s.router.Handler | ||
|
||
+ if s.cfg.BeforeHandler != nil { | ||
+ handler = func(ctx *fasthttp.RequestCtx) { | ||
+ s.cfg.BeforeHandler(ctx) | ||
+ s.router.Handler(ctx) | ||
+ } | ||
+ } | ||
+ | ||
if len(s.virtualHosts) > 0 { | ||
handler = func(ctx *fasthttp.RequestCtx) { | ||
hostname := strconv.B2S(ctx.URI().Host()) | ||
diff --git a/types.go b/types.go | ||
index 5265ec7..fce8b7d 100644 | ||
--- a/types.go | ||
+++ b/types.go | ||
@@ -369,6 +369,9 @@ type Config struct { // nolint:maligned | ||
// | ||
// NetHttpFormValueFunc gives a FormValueFunc func implementation that is consistent with net/http. | ||
FormValueFunc fasthttp.FormValueFunc | ||
+ | ||
+ // BeforeHandler Function to modify ctx before starting path handling. | ||
+ BeforeHandler func(ctx *fasthttp.RequestCtx) | ||
} | ||
|
||
// StaticFS represents settings for serving static files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters