Browse Source

Fixed default rule panic bug

Toby Chui 10 months ago
parent
commit
5e8be05efa
2 changed files with 5 additions and 0 deletions
  1. 4 0
      mod/access/access.go
  2. 1 0
      mod/dynamicproxy/access.go

+ 4 - 0
mod/access/access.go

@@ -69,6 +69,9 @@ func NewAccessController(options *Options) (*Controller, error) {
 		Options:           options,
 	}
 
+	//Assign default access rule parent
+	thisController.DefaultAccessRule.parent = &thisController
+
 	//Load all acccess rules from file
 	configFiles, err := filepath.Glob(options.ConfigFolder + "/*.json")
 	if err != nil {
@@ -113,6 +116,7 @@ func (c *Controller) GetGlobalAccessRule() (*AccessRule, error) {
 // Load access rules to runtime, require rule ID
 func (c *Controller) GetAccessRuleByID(accessRuleID string) (*AccessRule, error) {
 	if accessRuleID == "default" || accessRuleID == "" {
+
 		return c.DefaultAccessRule, nil
 	}
 	//Load from sync.Map, should be O(1)

+ 1 - 0
mod/dynamicproxy/access.go

@@ -21,6 +21,7 @@ func (h *ProxyHandler) handleAccessRouting(ruleID string, w http.ResponseWriter,
 		w.Write([]byte("500 - Internal Server Error"))
 		return true
 	}
+
 	isBlocked, blockedReason := accessRequestBlocked(accessRule, h.Parent.Option.WebDirectory, w, r)
 	if isBlocked {
 		h.logRequest(r, false, 403, blockedReason, "")