mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 17:28:31 +02:00
feat(rules): add protocol matching functionality
- Introduced a new checker for HTTP protocols (http, https, h3) in the routing rules. - Added corresponding test cases to validate protocol matching behavior in requests.
This commit is contained in:
@@ -31,6 +31,7 @@ const (
|
||||
OnCookie = "cookie"
|
||||
OnForm = "form"
|
||||
OnPostForm = "postform"
|
||||
OnProto = "proto"
|
||||
OnMethod = "method"
|
||||
OnHost = "host"
|
||||
OnPath = "path"
|
||||
@@ -226,6 +227,41 @@ var checkers = map[string]struct {
|
||||
}
|
||||
},
|
||||
},
|
||||
OnProto: {
|
||||
help: Help{
|
||||
command: OnProto,
|
||||
args: map[string]string{
|
||||
"proto": "the http protocol (http, https, h3)",
|
||||
},
|
||||
},
|
||||
validate: func(args []string) (any, gperr.Error) {
|
||||
if len(args) != 1 {
|
||||
return nil, ErrExpectOneArg
|
||||
}
|
||||
proto := args[0]
|
||||
if proto != "http" && proto != "https" && proto != "h3" {
|
||||
return nil, ErrInvalidArguments.Withf("proto: %q", proto)
|
||||
}
|
||||
return proto, nil
|
||||
},
|
||||
builder: func(args any) CheckFunc {
|
||||
proto := args.(string)
|
||||
switch proto {
|
||||
case "http":
|
||||
return func(w http.ResponseWriter, r *http.Request) bool {
|
||||
return r.TLS == nil
|
||||
}
|
||||
case "https":
|
||||
return func(w http.ResponseWriter, r *http.Request) bool {
|
||||
return r.TLS != nil
|
||||
}
|
||||
default: // h3
|
||||
return func(w http.ResponseWriter, r *http.Request) bool {
|
||||
return r.TLS != nil && r.ProtoMajor == 3
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
OnMethod: {
|
||||
help: Help{
|
||||
command: OnMethod,
|
||||
|
||||
Reference in New Issue
Block a user