From 0d3024b4861e526f062b1362ef7b3f978d27e5bd Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Tue, 21 Jun 2022 00:25:43 +0300 Subject: [PATCH] README: update sponsors --- README.md | 17 ++++++++++++++++- context/request_params.go | 2 +- core/router/handler.go | 27 ++++++++++++++++++--------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 793d8a29..40fe99d7 100644 --- a/README.md +++ b/README.md @@ -228,13 +228,14 @@ With your help, we can improve Open Source web development for everyone! celsosz TechMaster altafino + gf3 + alekperos hengestone thomasfr International Juanses ansrivas draFWM - gf3 lexrus li3p se77en @@ -246,6 +247,7 @@ With your help, we can improve Open Source web development for everyone! clacroix ixalender mubariz-ahmed + stgrosshh rodrigoghm Cesar DavidShaw @@ -291,6 +293,7 @@ With your help, we can improve Open Source web development for everyone! mark2b siriushaha spazzymoto + ehayun kukaki oshirokazuhide t6tg @@ -298,6 +301,7 @@ With your help, we can improve Open Source web development for everyone! BlackHole1 Jude-X KevinZhouRafael + KrishManohar Laotanling MihaiPopescu1985 Neulhan @@ -305,31 +309,40 @@ With your help, we can improve Open Source web development for everyone! SamuelNeves TianJIANG Ubun1 + YukinaMochizuki acdias agent3bood + annieruci b2cbd baoch254 bastengao + bjoroen bunnycodego carlos-enginner civicwar cnzhangquan edwindna2 fenriz07 + ffelipelimao gnosthi goten002 guanzi008 hdezoscar93 + homerious hzxd iantuan + jeremiahyan kana99 + keeio khasanovrs + kkdaypenny knavels leki75 liheyuan lingyingtan lipatti mattbowen + miguel-devs mizzlespot mnievesco motogo @@ -347,6 +360,7 @@ With your help, we can improve Open Source web development for everyone! rxrw saleebm sbenimeli + sebyno svirmi unixedia vguhesan @@ -356,6 +370,7 @@ With your help, we can improve Open Source web development for everyone! SergeShin blackHoleNgc1277 martinlindhe + mdamschen mtrense netbaalzovf lfaynman diff --git a/context/request_params.go b/context/request_params.go index ea9b6c0b..cc863758 100644 --- a/context/request_params.go +++ b/context/request_params.go @@ -48,7 +48,7 @@ func (r *RequestParams) Set(key, value string) { // Get returns a path parameter's value based on its route's dynamic path key. func (r *RequestParams) Get(key string) string { - for i := 0; i < len(r.Store); i++ { + for i := range r.Store { if kv := r.Store[i]; kv.Key == key { if v, ok := kv.ValueRaw.(string); ok { return v // it should always be string here on :string parameter. diff --git a/core/router/handler.go b/core/router/handler.go index 3ec5a483..87eaf9db 100644 --- a/core/router/handler.go +++ b/core/router/handler.go @@ -42,7 +42,13 @@ type ( ) type routerHandler struct { - config context.ConfigurationReadOnly + // Config. + disablePathCorrection bool + disablePathCorrectionRedirection bool + fireMethodNotAllowed bool + enablePathIntelligence bool + forceLowercaseRouting bool + // logger *golog.Logger trees []*trie @@ -60,8 +66,12 @@ var _ HTTPErrorHandler = (*routerHandler)(nil) // to map the request with a route (aka mux implementation). func NewDefaultHandler(config context.ConfigurationReadOnly, logger *golog.Logger) RequestHandler { return &routerHandler{ - config: config, - logger: logger, + disablePathCorrection: config.GetDisablePathCorrection(), + disablePathCorrectionRedirection: config.GetDisablePathCorrectionRedirection(), + fireMethodNotAllowed: config.GetFireMethodNotAllowed(), + enablePathIntelligence: config.GetEnablePathIntelligence(), + forceLowercaseRouting: config.GetForceLowercaseRouting(), + logger: logger, } } @@ -200,7 +210,7 @@ func (h *routerHandler) Build(provider RoutesProvider) error { noLogCount++ } - if h.config != nil && h.config.GetForceLowercaseRouting() { + if h.forceLowercaseRouting { // only in that state, keep everything else as end-developer registered. r.Path = strings.ToLower(r.Path) } @@ -393,9 +403,8 @@ func canHandleSubdomain(ctx *context.Context, subdomain string) bool { func (h *routerHandler) HandleRequest(ctx *context.Context) { method := ctx.Method() path := ctx.Path() - config := h.config // ctx.Application().GetConfigurationReadOnly() - if !config.GetDisablePathCorrection() { + if !h.disablePathCorrection { if len(path) > 1 && strings.HasSuffix(path, "/") { // Remove trailing slash and client-permanent rule for redirection, // if confgiuration allows that and path has an extra slash. @@ -405,7 +414,7 @@ func (h *routerHandler) HandleRequest(ctx *context.Context) { // use Trim to ensure there is no open redirect due to two leading slashes path = "/" + strings.Trim(path, "/") u.Path = path - if !config.GetDisablePathCorrectionRedirection() { + if !h.disablePathCorrectionRedirection { // do redirect, else continue with the modified path without the last "/". url := u.String() @@ -445,7 +454,7 @@ func (h *routerHandler) HandleRequest(ctx *context.Context) { break } - if config.GetFireMethodNotAllowed() { + if h.fireMethodNotAllowed { for i := range h.trees { t := h.trees[i] // if `Configuration#FireMethodNotAllowed` is kept as defaulted(false) then this function will not @@ -460,7 +469,7 @@ func (h *routerHandler) HandleRequest(ctx *context.Context) { } } - if config.GetEnablePathIntelligence() && method == http.MethodGet { + if h.enablePathIntelligence && method == http.MethodGet { closestPaths := ctx.FindClosest(1) if len(closestPaths) > 0 { u := ctx.Request().URL