Skip to content

Commit 026df7c

Browse files
committed
reverse_proxy: WIP refactor and support for FastCGI
1 parent 2dc4fcc commit 026df7c

17 files changed

Lines changed: 2741 additions & 888 deletions

‎cmd/caddy/main.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/markdown"
3030
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/requestbody"
3131
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy"
32+
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi"
3233
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
3334
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/templates"
3435
_ "github.com/caddyserver/caddy/v2/modules/caddytls"

‎go.mod‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/Masterminds/semver v1.4.2 // indirect
99
github.com/Masterminds/sprig v2.20.0+incompatible
1010
github.com/andybalholm/brotli v0.0.0-20190704151324-71eb68cc467c
11-
github.com/davecgh/go-spew v1.1.1 // indirect
1211
github.com/dustin/go-humanize v1.0.0
1312
github.com/go-acme/lego v2.6.0+incompatible
1413
github.com/google/go-cmp v0.3.1 // indirect
@@ -17,7 +16,6 @@ require (
1716
github.com/imdario/mergo v0.3.7 // indirect
1817
github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b
1918
github.com/klauspost/cpuid v1.2.1
20-
github.com/kr/pretty v0.1.0 // indirect
2119
github.com/mholt/certmagic v0.6.2
2220
github.com/mitchellh/go-ps v0.0.0-20170309133038-4fdf99ab2936
2321
github.com/rs/cors v1.6.0
@@ -26,8 +24,7 @@ require (
2624
github.com/starlight-go/starlight v0.0.0-20181207205707-b06f321544f3
2725
go.starlark.net v0.0.0-20190604130855-6ddc71c0ba77
2826
golang.org/x/net v0.0.0-20190603091049-60506f45cf65
29-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 // indirect
27+
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e // indirect
3028
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
31-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
3229
gopkg.in/yaml.v2 v2.2.2 // indirect
3330
)

‎go.sum‎

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1q
1212
github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
1313
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
1414
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
16-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1715
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
1816
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
1917
github.com/go-acme/lego v2.5.0+incompatible/go.mod h1:yzMNe9CasVUhkquNvti5nAtPmG94USbYxYrZfTkIn0M=
@@ -34,11 +32,6 @@ github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b/go.mod h1:RyI
3432
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
3533
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
3634
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
37-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
38-
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
39-
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
40-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
41-
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
4235
github.com/mholt/certmagic v0.6.2 h1:yy9cKm3rtxdh12SW4E51lzG3Eo6N59LEOfBQ0CTnMms=
4336
github.com/mholt/certmagic v0.6.2/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
4437
github.com/miekg/dns v1.1.3 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM=
@@ -71,16 +64,14 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
7164
golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7265
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
7366
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
74-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
75-
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
67+
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e h1:ZytStCyV048ZqDsWHiYDdoI2Vd4msMcrDECFxS+tL9c=
68+
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
7669
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
7770
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
7871
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
7972
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
8073
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8174
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
82-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
83-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8475
gopkg.in/square/go-jose.v2 v2.2.2 h1:orlkJ3myw8CN1nVQHBFfloD+L3egixIa4FvUP6RosSA=
8576
gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
8677
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=

‎listeners.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"time"
2525
)
2626

27+
// TODO: Can we use the new UsagePool type?
28+
2729
// Listen returns a listener suitable for use in a Caddy module.
2830
// Always be sure to close listeners when you are done with them.
2931
func Listen(network, addr string) (net.Listener, error) {

‎modules/caddyhttp/caddyhttp.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,20 @@ func (ws WeakString) String() string {
518518
return string(ws)
519519
}
520520

521+
// StatusCodeMatches returns true if a real HTTP status code matches
522+
// the configured status code, which may be either a real HTTP status
523+
// code or an integer representing a class of codes (e.g. 4 for all
524+
// 4xx statuses).
525+
func StatusCodeMatches(actual, configured int) bool {
526+
if actual == configured {
527+
return true
528+
}
529+
if configured < 100 && actual >= configured*100 && actual < (configured+1)*100 {
530+
return true
531+
}
532+
return false
533+
}
534+
521535
const (
522536
// DefaultHTTPPort is the default port for HTTP.
523537
DefaultHTTPPort = 80

‎modules/caddyhttp/matchers.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,7 @@ func (rm ResponseMatcher) matchStatusCode(statusCode int) bool {
616616
return true
617617
}
618618
for _, code := range rm.StatusCode {
619-
if statusCode == code {
620-
return true
621-
}
622-
if code < 100 && statusCode >= code*100 && statusCode < (code+1)*100 {
619+
if StatusCodeMatches(statusCode, code) {
623620
return true
624621
}
625622
}

0 commit comments

Comments
 (0)