Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
caddyhttp: CEL matcher checks return type; slight refactor
As per https://github.com/caddyserver/caddy/issues/3051#issuecomment-611200414
Matthew Holt committed
Apr 8, 2020 at 15:39 UTC
e5dc76b05406ece7e2c1a9567bb18a47d7873793
3 files changed
+10
-7
go.mod
+1
@@ -10,6 +10,7 @@ require (
10
github.com/cenkalti/backoff/v4 v4.0.2 // indirect
11
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
12
github.com/go-acme/lego/v3 v3.5.0
13
+ github.com/gogo/protobuf v1.3.1
14
github.com/google/cel-go v0.4.1
15
github.com/jsternberg/zap-logfmt v1.2.0
16
github.com/klauspost/compress v1.10.3
go.sum
+1
@@ -249,6 +249,7 @@ github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRx
249
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
250
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
251
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
252
+github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
253
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
254
github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A=
255
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
modules/caddyhttp/celmatcher.go
+8
-7
@@ -24,6 +24,7 @@ import (
24
25
"github.com/caddyserver/caddy/v2"
26
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
27
+ "github.com/gogo/protobuf/proto"
28
"github.com/google/cel-go/cel"
29
"github.com/google/cel-go/checker/decls"
30
"github.com/google/cel-go/common/types"
@@ -99,16 +100,16 @@ func (m *MatchExpression) Provision(_ caddy.Context) error {
100
return fmt.Errorf("setting up CEL environment: %v", err)
101
}
102
102
- // parse the expression
103
- parsed, issues := env.Parse(m.expandedExpr)
103
+ // parse and type-check the expression
104
+ checked, issues := env.Compile(m.expandedExpr)
105
if issues != nil && issues.Err() != nil {
105
- return fmt.Errorf("parsing CEL program: %s", issues.Err())
106
+ return fmt.Errorf("compiling CEL program: %s", issues.Err())
107
}
108
108
- // type-check it
109
- checked, issues := env.Check(parsed)
110
- if issues != nil && issues.Err() != nil {
111
- return fmt.Errorf("type-checking CEL program: %s", issues.Err())
109
+ // request matching is a boolean operation, so we don't really know
110
+ // what to do if the expression returns a non-boolean type
111
+ if !proto.Equal(checked.ResultType(), decls.Bool) {
112
+ return fmt.Errorf("CEL request matcher expects return type of bool, not %s", checked.ResultType())
113
}
114
115
// compile the "program"