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
Remove some non-essential plugins from this repo (#2780)
Brotli encoder, jsonc and json5 config adapters, and the unfinished HTTP cache handler are removed. They will be available in separate repos.
Matthew Holt committed
Mar 24, 2020 at 10:37 UTC
341d4fb8059f6aad5d371514fb851256add327cf
11 files changed
+27
-465
caddyconfig/json5/json5.go
deleted
-43
@@ -1,43 +0,0 @@
1
-// Copyright 2015 Matthew Holt and The Caddy Authors
2
-//
3
-// Licensed under the Apache License, Version 2.0 (the "License");
4
-// you may not use this file except in compliance with the License.
5
-// You may obtain a copy of the License at
6
-//
7
-// http://www.apache.org/licenses/LICENSE-2.0
8
-//
9
-// Unless required by applicable law or agreed to in writing, software
10
-// distributed under the License is distributed on an "AS IS" BASIS,
11
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-// See the License for the specific language governing permissions and
13
-// limitations under the License.
14
-
15
-package json5adapter
16
-
17
-import (
18
- "encoding/json"
19
-
20
- "github.com/caddyserver/caddy/v2/caddyconfig"
21
- "github.com/ilibs/json5"
22
-)
23
-
24
-func init() {
25
- caddyconfig.RegisterAdapter("json5", Adapter{})
26
-}
27
-
28
-// Adapter adapts JSON5 to Caddy JSON.
29
-type Adapter struct{}
30
-
31
-// Adapt converts the JSON5 config in body to Caddy JSON.
32
-func (a Adapter) Adapt(body []byte, options map[string]interface{}) (result []byte, warnings []caddyconfig.Warning, err error) {
33
- var decoded interface{}
34
- err = json5.Unmarshal(body, &decoded)
35
- if err != nil {
36
- return
37
- }
38
- result, err = json.Marshal(decoded)
39
- return
40
-}
41
-
42
-// Interface guard
43
-var _ caddyconfig.Adapter = (*Adapter)(nil)
caddyconfig/jsonc/jsonc.go
deleted
-49
@@ -1,49 +0,0 @@
1
-// Copyright 2015 Matthew Holt and The Caddy Authors
2
-//
3
-// Licensed under the Apache License, Version 2.0 (the "License");
4
-// you may not use this file except in compliance with the License.
5
-// You may obtain a copy of the License at
6
-//
7
-// http://www.apache.org/licenses/LICENSE-2.0
8
-//
9
-// Unless required by applicable law or agreed to in writing, software
10
-// distributed under the License is distributed on an "AS IS" BASIS,
11
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-// See the License for the specific language governing permissions and
13
-// limitations under the License.
14
-
15
-package jsoncadapter
16
-
17
-import (
18
- "encoding/json"
19
-
20
- "github.com/caddyserver/caddy/v2/caddyconfig"
21
- "github.com/muhammadmuzzammil1998/jsonc"
22
-)
23
-
24
-func init() {
25
- caddyconfig.RegisterAdapter("jsonc", Adapter{})
26
-}
27
-
28
-// Adapter adapts JSON-C to Caddy JSON.
29
-type Adapter struct{}
30
-
31
-// Adapt converts the JSON-C config in body to Caddy JSON.
32
-func (a Adapter) Adapt(body []byte, options map[string]interface{}) (result []byte, warnings []caddyconfig.Warning, err error) {
33
- result = jsonc.ToJSON(body)
34
-
35
- // any errors in the JSON will be
36
- // reported during config load, but
37
- // we can at least warn here that
38
- // it is not valid JSON
39
- if !json.Valid(result) {
40
- warnings = append(warnings, caddyconfig.Warning{
41
- Message: "Resulting JSON is invalid.",
42
- })
43
- }
44
-
45
- return
46
-}
47
-
48
-// Interface guard
49
-var _ caddyconfig.Adapter = (*Adapter)(nil)
go.mod
+4
-8
@@ -5,32 +5,28 @@ go 1.14
5
require (
6
github.com/Masterminds/sprig/v3 v3.0.2
7
github.com/alecthomas/chroma v0.7.2-0.20200305040604-4f3623dce67a
8
- github.com/andybalholm/brotli v1.0.0
8
github.com/caddyserver/certmagic v0.10.4
9
github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac
10
github.com/go-acme/lego/v3 v3.5.0
12
- github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
11
github.com/google/cel-go v0.4.0
14
- github.com/ilibs/json5 v1.0.1
12
github.com/jsternberg/zap-logfmt v1.2.0
13
github.com/klauspost/compress v1.10.3
14
github.com/klauspost/cpuid v1.2.3
15
github.com/lucas-clemente/quic-go v0.15.2
16
github.com/manifoldco/promptui v0.7.0 // indirect
17
github.com/miekg/dns v1.1.29 // indirect
21
- github.com/muhammadmuzzammil1998/jsonc v0.0.0-20200303171503-1e787b591db7
18
github.com/naoina/go-stringutil v0.1.0 // indirect
19
github.com/naoina/toml v0.1.1
20
github.com/smallstep/certificates v0.14.0-rc.5
21
github.com/smallstep/cli v0.14.0-rc.3
22
github.com/smallstep/truststore v0.9.4
27
- github.com/vulcand/oxy v1.0.0
23
+ github.com/vulcand/oxy v1.1.0
24
github.com/yuin/goldmark v1.1.25
25
github.com/yuin/goldmark-highlighting v0.0.0-20200307114337-60d527fdb691
26
go.uber.org/zap v1.14.1
31
- golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6
32
- golang.org/x/net v0.0.0-20200319234117-63522dbf7eec
33
- google.golang.org/genproto v0.0.0-20200305110556-506484158171
27
+ golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
28
+ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
29
+ google.golang.org/genproto v0.0.0-20200323114720-3f67cca34472
30
gopkg.in/natefinch/lumberjack.v2 v2.0.0
31
gopkg.in/square/go-jose.v2 v2.4.1 // indirect
32
gopkg.in/yaml.v2 v2.2.8
go.sum
+12
-12
@@ -100,8 +100,6 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
100
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee h1:NYqDBPkhVYt68W3yoGoRRi32i3MLx2ey7SFkJ1v/UI0=
101
github.com/aliyun/alibaba-cloud-sdk-go v0.0.0-20190808125512-07798873deee/go.mod h1:myCDvQSzCW+wB1WAlocEru4wMGJxy+vlxHdhegi1CDQ=
102
github.com/aliyun/aliyun-oss-go-sdk v0.0.0-20190307165228-86c17b95fcd5/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
103
-github.com/andybalholm/brotli v1.0.0 h1:7UCwP93aiSfvWpapti8g88vVVGp2qqtGyePsSuDafo4=
104
-github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
103
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
104
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q=
105
github.com/antlr/antlr4 v0.0.0-20190819145818-b43a4c3a8015 h1:StuiJFxQUsxSCzcby6NFZRdEhPkXD5vxN7TZ4MD6T84=
@@ -344,6 +342,7 @@ github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
342
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
343
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
344
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
345
+github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
346
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
347
github.com/gostaticanalysis/analysisutil v0.0.3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
348
github.com/gravitational/trace v0.0.0-20190726142706-a535a178675f/go.mod h1:RvdOUHE4SHqR3oXlFFKnGzms8a5dugHygGw1bqDstYI=
@@ -368,8 +367,6 @@ github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63
367
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
368
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428/go.mod h1:uhpZMVGznybq1itEKXj6RYw9I71qK4kH+OGMjRC4KEo=
369
github.com/iij/doapi v0.0.0-20190504054126-0bbf12d6d7df/go.mod h1:QMZY7/J/KSQEhKWFeDesPjMj+wCHReeknARU3wqlyN4=
371
-github.com/ilibs/json5 v1.0.1 h1:3e14wUQM8PyK6Hf1bM+zAQFxfG+N5oZj35x5vCNeQ58=
372
-github.com/ilibs/json5 v1.0.1/go.mod h1:kXsGuzHMPuZZTN15l0IQzy5PR8DrDhPB24tFgwpdKME=
370
github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
371
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
372
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
@@ -498,8 +495,6 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
495
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
496
github.com/mozilla/tls-observatory v0.0.0-20180409132520-8791a200eb40/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
497
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
501
-github.com/muhammadmuzzammil1998/jsonc v0.0.0-20200303171503-1e787b591db7 h1:IhnWtz7gaLvL0wn8xr86ERSvSmwNAsaHMRAqgsu/CVQ=
502
-github.com/muhammadmuzzammil1998/jsonc v0.0.0-20200303171503-1e787b591db7/go.mod h1:saF2fIVw4banK0H4+/EuqfFLpRnoy5S+ECwTOCcRcSU=
498
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
499
github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8=
500
github.com/naoina/go-stringutil v0.1.0 h1:rCUeRUHjBjGTSHl0VC00jUPLz8/F9dDzYI70Hzifhks=
@@ -750,8 +745,8 @@ github.com/valyala/quicktemplate v1.2.0/go.mod h1:EH+4AkTd43SvgIbQHYu59/cJyxDoOV
745
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
746
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
747
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
753
-github.com/vulcand/oxy v1.0.0 h1:7vL5/pjDFzHGbtBEhmlHITUi6KLH4xXTDF33/wrdRKw=
754
-github.com/vulcand/oxy v1.0.0/go.mod h1:6EXgOAl6CRa46/2ZGcDJKf3ywJUp5WtT7vSlGSkvecI=
748
+github.com/vulcand/oxy v1.1.0 h1:DbBijGo1+6cFqR9jarkMxasdj0lgWwrrFtue6ijek4Q=
749
+github.com/vulcand/oxy v1.1.0/go.mod h1:ADiMYHi8gkGl2987yQIzDRoXZilANF4WtKaQ92OppKY=
750
github.com/vulcand/predicate v1.1.0/go.mod h1:mlccC5IRBoc2cIFmCB8ZM62I3VDb6p2GXESMHa3CnZg=
751
github.com/vultr/govultr v0.1.4/go.mod h1:9H008Uxr/C4vFNGLqKx232C206GL0PBHzOP0809bGNA=
752
github.com/weppos/publicsuffix-go v0.4.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
@@ -824,8 +819,8 @@ golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPh
819
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
820
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
821
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
827
-golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6 h1:TjszyFsQsyZNHwdVdZ5m7bjmreu0znc2kRYsEml9/Ww=
828
-golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
822
+golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59 h1:3zb4D3T4G8jdExgVU/95+vQXfpEPiMdCaZgmGVxjNHM=
823
+golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
824
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
825
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
826
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -896,8 +891,8 @@ golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLL
891
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
892
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
893
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
899
-golang.org/x/net v0.0.0-20200319234117-63522dbf7eec h1:w0SItUiQ4sBiXBAwWNkyu8Fu2Qpn/dtDIcoPkPDqjRw=
900
-golang.org/x/net v0.0.0-20200319234117-63522dbf7eec/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
894
+golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
895
+golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
896
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
897
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
898
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -963,6 +958,8 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepx
958
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
959
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
960
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
961
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
962
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
963
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
964
golang.org/x/text v0.0.0-20170915090833-1cbadb444a80/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
965
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1089,6 +1086,8 @@ google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfG
1086
google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
1087
google.golang.org/genproto v0.0.0-20200305110556-506484158171 h1:xes2Q2k+d/+YNXVw0FpZkIDJiaux4OVrRKXRAzH6A0U=
1088
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
1089
+google.golang.org/genproto v0.0.0-20200323114720-3f67cca34472 h1:XRuIAeTRoXziYGYTVer+YGxVXQBiOhZ8+SpNELP73oQ=
1090
+google.golang.org/genproto v0.0.0-20200323114720-3f67cca34472/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
1091
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
1092
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
1093
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
@@ -1158,6 +1157,7 @@ honnef.co/go/tools v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3
1157
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
1158
howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M=
1159
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
1160
+launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
1161
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
1162
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
1163
mvdan.cc/unparam v0.0.0-20190209190245-fbb59629db34/go.mod h1:H6SUd1XjIs+qQCyskXg5OFSrilMRUkD8ePJpHKDPaeY=
modules/caddyhttp/encode/brotli/brotli.go
deleted
-95
@@ -1,95 +0,0 @@
1
-// Copyright 2015 Matthew Holt and The Caddy Authors
2
-//
3
-// Licensed under the Apache License, Version 2.0 (the "License");
4
-// you may not use this file except in compliance with the License.
5
-// You may obtain a copy of the License at
6
-//
7
-// http://www.apache.org/licenses/LICENSE-2.0
8
-//
9
-// Unless required by applicable law or agreed to in writing, software
10
-// distributed under the License is distributed on an "AS IS" BASIS,
11
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-// See the License for the specific language governing permissions and
13
-// limitations under the License.
14
-
15
-package caddybrotli
16
-
17
-import (
18
- "fmt"
19
- "strconv"
20
-
21
- "github.com/andybalholm/brotli"
22
- "github.com/caddyserver/caddy/v2"
23
- "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
24
- "github.com/caddyserver/caddy/v2/modules/caddyhttp/encode"
25
-)
26
-
27
-func init() {
28
- caddy.RegisterModule(Brotli{})
29
-}
30
-
31
-// Brotli can create brotli encoders. Note that brotli
32
-// is not known for great encoding performance, and
33
-// its use during requests is discouraged; instead,
34
-// pre-compress the content instead.
35
-type Brotli struct {
36
- Quality *int `json:"quality,omitempty"`
37
-}
38
-
39
-// CaddyModule returns the Caddy module information.
40
-func (Brotli) CaddyModule() caddy.ModuleInfo {
41
- return caddy.ModuleInfo{
42
- ID: "http.encoders.brotli",
43
- New: func() caddy.Module { return new(Brotli) },
44
- }
45
-}
46
-
47
-// UnmarshalCaddyfile sets up the handler from Caddyfile tokens.
48
-func (b *Brotli) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
49
- for d.Next() {
50
- if !d.NextArg() {
51
- continue
52
- }
53
- qualityStr := d.Val()
54
- quality, err := strconv.Atoi(qualityStr)
55
- if err != nil {
56
- return err
57
- }
58
- b.Quality = &quality
59
- }
60
- return nil
61
-}
62
-
63
-// Validate validates b's configuration.
64
-func (b Brotli) Validate() error {
65
- if b.Quality != nil {
66
- quality := *b.Quality
67
- if quality < brotli.BestSpeed {
68
- return fmt.Errorf("quality too low; must be >= %d", brotli.BestSpeed)
69
- }
70
- if quality > brotli.BestCompression {
71
- return fmt.Errorf("quality too high; must be <= %d", brotli.BestCompression)
72
- }
73
- }
74
- return nil
75
-}
76
-
77
-// AcceptEncoding returns the name of the encoding as
78
-// used in the Accept-Encoding request headers.
79
-func (Brotli) AcceptEncoding() string { return "br" }
80
-
81
-// NewEncoder returns a new brotli writer.
82
-func (b Brotli) NewEncoder() encode.Encoder {
83
- quality := brotli.DefaultCompression
84
- if b.Quality != nil {
85
- quality = *b.Quality
86
- }
87
- return brotli.NewWriterLevel(nil, quality)
88
-}
89
-
90
-// Interface guards
91
-var (
92
- _ encode.Encoding = (*Brotli)(nil)
93
- _ caddy.Validator = (*Brotli)(nil)
94
- _ caddyfile.Unmarshaler = (*Brotli)(nil)
95
-)
modules/caddyhttp/encode/caddyfile.go
-1
@@ -42,7 +42,6 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
42
// encode [<matcher>] <formats...> {
43
// gzip [<level>]
44
// zstd
45
-// brotli [<quality>]
45
// }
46
//
47
// Specifying the formats on the first line will use those formats' defaults.
modules/caddyhttp/httpcache/httpcache.go
deleted
-242
@@ -1,242 +0,0 @@
1
-// Copyright 2015 Matthew Holt and The Caddy Authors
2
-//
3
-// Licensed under the Apache License, Version 2.0 (the "License");
4
-// you may not use this file except in compliance with the License.
5
-// You may obtain a copy of the License at
6
-//
7
-// http://www.apache.org/licenses/LICENSE-2.0
8
-//
9
-// Unless required by applicable law or agreed to in writing, software
10
-// distributed under the License is distributed on an "AS IS" BASIS,
11
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
-// See the License for the specific language governing permissions and
13
-// limitations under the License.
14
-
15
-package httpcache
16
-
17
-import (
18
- "bytes"
19
- "context"
20
- "encoding/gob"
21
- "fmt"
22
- "io"
23
- "log"
24
- "net/http"
25
- "sync"
26
-
27
- "github.com/caddyserver/caddy/v2"
28
- "github.com/caddyserver/caddy/v2/modules/caddyhttp"
29
- "github.com/golang/groupcache"
30
-)
31
-
32
-func init() {
33
- caddy.RegisterModule(Cache{})
34
-}
35
-
36
-// Cache implements a simple distributed cache.
37
-//
38
-// NOTE: This module is a work-in-progress. It is
39
-// not finished and is NOT ready for production use.
40
-// [We need your help to finish it! Please volunteer
41
-// in this issue.](https://github.com/caddyserver/caddy/issues/2820)
42
-// Until it is finished, this module is subject to
43
-// breaking changes.
44
-//
45
-// Caches only GET and HEAD requests. Honors the Cache-Control: no-cache header.
46
-//
47
-// Still TODO:
48
-//
49
-// - Eviction policies and API
50
-// - Use single cache per-process
51
-// - Preserve cache through config reloads
52
-// - More control over what gets cached
53
-type Cache struct {
54
- // The network address of this cache instance; required.
55
- Self string `json:"self,omitempty"`
56
-
57
- // A list of network addresses of cache instances in the group.
58
- Peers []string `json:"peers,omitempty"`
59
-
60
- // Maximum size of the cache, in bytes. Default is 512 MB.
61
- MaxSize int64 `json:"max_size,omitempty"`
62
-
63
- group *groupcache.Group
64
-}
65
-
66
-// CaddyModule returns the Caddy module information.
67
-func (Cache) CaddyModule() caddy.ModuleInfo {
68
- return caddy.ModuleInfo{
69
- ID: "http.handlers.cache",
70
- New: func() caddy.Module { return new(Cache) },
71
- }
72
-}
73
-
74
-// Provision provisions c.
75
-func (c *Cache) Provision(ctx caddy.Context) error {
76
- // TODO: use UsagePool so that cache survives config reloads - TODO: a single cache for whole process?
77
- maxSize := c.MaxSize
78
- if maxSize == 0 {
79
- const maxMB = 512
80
- maxSize = int64(maxMB << 20)
81
- }
82
- poolMu.Lock()
83
- if pool == nil {
84
- pool = groupcache.NewHTTPPool(c.Self)
85
- c.group = groupcache.NewGroup(groupName, maxSize, groupcache.GetterFunc(c.getter))
86
- } else {
87
- c.group = groupcache.GetGroup(groupName)
88
- }
89
- pool.Set(append(c.Peers, c.Self)...)
90
- poolMu.Unlock()
91
-
92
- return nil
93
-}
94
-
95
-// Validate validates c.
96
-func (c *Cache) Validate() error {
97
- if c.Self == "" {
98
- return fmt.Errorf("address of this instance (self) is required")
99
- }
100
- if c.MaxSize < 0 {
101
- return fmt.Errorf("size must be greater than 0")
102
- }
103
- return nil
104
-}
105
-
106
-func (c *Cache) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
107
- // TODO: proper RFC implementation of cache control headers...
108
- if r.Header.Get("Cache-Control") == "no-cache" || (r.Method != "GET" && r.Method != "HEAD") {
109
- return next.ServeHTTP(w, r)
110
- }
111
-
112
- getterCtx := getterContext{w, r, next}
113
- ctx := context.WithValue(r.Context(), getterContextCtxKey, getterCtx)
114
-
115
- // TODO: rigorous performance testing
116
-
117
- // TODO: pretty much everything else to handle the nuances of HTTP caching...
118
-
119
- // TODO: groupcache has no explicit cache eviction, so we need to embed
120
- // all information related to expiring cache entries into the key; right
121
- // now we just use the request URI as a proof-of-concept
122
- key := r.RequestURI
123
-
124
- var cachedBytes []byte
125
- err := c.group.Get(ctx, key, groupcache.AllocatingByteSliceSink(&cachedBytes))
126
- if err == errUncacheable {
127
- return nil
128
- }
129
- if err != nil {
130
- return err
131
- }
132
-
133
- // the cached bytes consists of two parts: first a
134
- // gob encoding of the status and header, immediately
135
- // followed by the raw bytes of the response body
136
- rdr := bytes.NewReader(cachedBytes)
137
-
138
- // read the header and status first
139
- var hs headerAndStatus
140
- err = gob.NewDecoder(rdr).Decode(&hs)
141
- if err != nil {
142
- return err
143
- }
144
-
145
- // set and write the cached headers
146
- for k, v := range hs.Header {
147
- w.Header()[k] = v
148
- }
149
- w.WriteHeader(hs.Status)
150
-
151
- // write the cached response body
152
- io.Copy(w, rdr)
153
-
154
- return nil
155
-}
156
-
157
-func (c *Cache) getter(ctx context.Context, key string, dest groupcache.Sink) error {
158
- combo := ctx.Value(getterContextCtxKey).(getterContext)
159
-
160
- // the buffer will store the gob-encoded header, then the body
161
- buf := bufPool.Get().(*bytes.Buffer)
162
- buf.Reset()
163
- defer bufPool.Put(buf)
164
-
165
- // we need to record the response if we are to cache it; only cache if
166
- // request is successful (TODO: there's probably much more nuance needed here)
167
- rr := caddyhttp.NewResponseRecorder(combo.rw, buf, func(status int, header http.Header) bool {
168
- shouldBuf := status < 300
169
-
170
- if shouldBuf {
171
- // store the header before the body, so we can efficiently
172
- // and conveniently use a single buffer for both; gob
173
- // decoder will only read up to end of gob message, and
174
- // the rest will be the body, which will be written
175
- // implicitly for us by the recorder
176
- err := gob.NewEncoder(buf).Encode(headerAndStatus{
177
- Header: header,
178
- Status: status,
179
- })
180
- if err != nil {
181
- log.Printf("[ERROR] Encoding headers for cache entry: %v; not caching this request", err)
182
- return false
183
- }
184
- }
185
-
186
- return shouldBuf
187
- })
188
-
189
- // execute next handlers in chain
190
- err := combo.next.ServeHTTP(rr, combo.req)
191
- if err != nil {
192
- return err
193
- }
194
-
195
- // if response body was not buffered, response was
196
- // already written and we are unable to cache
197
- if !rr.Buffered() {
198
- return errUncacheable
199
- }
200
-
201
- // add to cache
202
- dest.SetBytes(buf.Bytes())
203
-
204
- return nil
205
-}
206
-
207
-type headerAndStatus struct {
208
- Header http.Header
209
- Status int
210
-}
211
-
212
-type getterContext struct {
213
- rw http.ResponseWriter
214
- req *http.Request
215
- next caddyhttp.Handler
216
-}
217
-
218
-var bufPool = sync.Pool{
219
- New: func() interface{} {
220
- return new(bytes.Buffer)
221
- },
222
-}
223
-
224
-var (
225
- pool *groupcache.HTTPPool
226
- poolMu sync.Mutex
227
-)
228
-
229
-var errUncacheable = fmt.Errorf("uncacheable")
230
-
231
-const groupName = "http_requests"
232
-
233
-type ctxKey string
234
-
235
-const getterContextCtxKey ctxKey = "getter_context"
236
-
237
-// Interface guards
238
-var (
239
- _ caddy.Provisioner = (*Cache)(nil)
240
- _ caddy.Validator = (*Cache)(nil)
241
- _ caddyhttp.MiddlewareHandler = (*Cache)(nil)
242
-)
modules/caddyhttp/requestbody/requestbody.go
+1
-1
@@ -34,7 +34,7 @@ type RequestBody struct {
34
// CaddyModule returns the Caddy module information.
35
func (RequestBody) CaddyModule() caddy.ModuleInfo {
36
return caddy.ModuleInfo{
37
- ID: "http.handlers.request_body", // TODO: better name for this?
37
+ ID: "http.handlers.request_body",
38
New: func() caddy.Module { return new(RequestBody) },
39
}
40
}
modules/caddyhttp/reverseproxy/circuitbreaker.go
+10
-10
@@ -24,12 +24,12 @@ import (
24
)
25
26
func init() {
27
- caddy.RegisterModule(localCircuitBreaker{})
27
+ caddy.RegisterModule(internalCircuitBreaker{})
28
}
29
30
-// localCircuitBreaker implements circuit breaking functionality
30
+// internalCircuitBreaker implements circuit breaking functionality
31
// for requests within this process over a sliding time window.
32
-type localCircuitBreaker struct {
32
+type internalCircuitBreaker struct {
33
tripped int32
34
cbFactor int32
35
threshold float64
@@ -39,15 +39,15 @@ type localCircuitBreaker struct {
39
}
40
41
// CaddyModule returns the Caddy module information.
42
-func (localCircuitBreaker) CaddyModule() caddy.ModuleInfo {
42
+func (internalCircuitBreaker) CaddyModule() caddy.ModuleInfo {
43
return caddy.ModuleInfo{
44
- ID: "http.reverse_proxy.circuit_breakers.local",
45
- New: func() caddy.Module { return new(localCircuitBreaker) },
44
+ ID: "http.reverse_proxy.circuit_breakers.internal",
45
+ New: func() caddy.Module { return new(internalCircuitBreaker) },
46
}
47
}
48
49
// Provision sets up a configured circuit breaker.
50
-func (c *localCircuitBreaker) Provision(ctx caddy.Context) error {
50
+func (c *internalCircuitBreaker) Provision(ctx caddy.Context) error {
51
f, ok := typeCB[c.Factor]
52
if !ok {
53
return fmt.Errorf("type is not defined")
@@ -77,19 +77,19 @@ func (c *localCircuitBreaker) Provision(ctx caddy.Context) error {
77
}
78
79
// Ok returns whether the circuit breaker is tripped or not.
80
-func (c *localCircuitBreaker) Ok() bool {
80
+func (c *internalCircuitBreaker) Ok() bool {
81
tripped := atomic.LoadInt32(&c.tripped)
82
return tripped == 0
83
}
84
85
// RecordMetric records a response status code and execution time of a request. This function should be run in a separate goroutine.
86
-func (c *localCircuitBreaker) RecordMetric(statusCode int, latency time.Duration) {
86
+func (c *internalCircuitBreaker) RecordMetric(statusCode int, latency time.Duration) {
87
c.metrics.Record(statusCode, latency)
88
c.checkAndSet()
89
}
90
91
// Ok checks our metrics to see if we should trip our circuit breaker, or if the fallback duration has completed.
92
-func (c *localCircuitBreaker) checkAndSet() {
92
+func (c *internalCircuitBreaker) checkAndSet() {
93
var isTripped bool
94
95
switch c.cbFactor {
modules/caddyhttp/standard/imports.go
-2
@@ -5,12 +5,10 @@ import (
5
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp"
6
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth"
7
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/encode"
8
- _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/encode/brotli"
8
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/encode/gzip"
9
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/encode/zstd"
10
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver"
11
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
13
- _ "github.com/caddyserver/caddy/v2/modules/caddyhttp/httpcache"
12
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/requestbody"
13
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy"
14
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/reverseproxy/fastcgi"
modules/standard/import.go
-2
@@ -3,8 +3,6 @@ package standard
3
import (
4
// standard Caddy modules
5
_ "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
6
- _ "github.com/caddyserver/caddy/v2/caddyconfig/json5"
7
- _ "github.com/caddyserver/caddy/v2/caddyconfig/jsonc"
6
_ "github.com/caddyserver/caddy/v2/modules/caddyhttp/standard"
7
_ "github.com/caddyserver/caddy/v2/modules/caddypki"
8
_ "github.com/caddyserver/caddy/v2/modules/caddytls"