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
requestbody: Add Caddyfile support (#3859)
* Add Caddyfile support for request_body: ``` request_body { max_size 10000000 } ``` * Improve Caddyfile parser for request_body module * Remove unnecessary `continue` * Add sample for caddyfile_adapt_test
Nicola Piccinini committed
Nov 16, 2020 at 19:43 UTC
670b723e3802ac37942dad07dc194539bccce9ff
3 files changed
+97
caddyconfig/httpcaddyfile/directives.go
+1
@@ -41,6 +41,7 @@ var directiveOrder = []string{
41
"root",
42
43
"header",
44
+ "request_body",
45
46
"redir",
47
"rewrite",
caddytest/integration/caddyfile_adapt/request_body.txt
new
+45
@@ -0,0 +1,45 @@
1
+localhost
2
+request_body {
3
+ max_size 1MB
4
+}
5
+----------
6
+{
7
+ "apps": {
8
+ "http": {
9
+ "servers": {
10
+ "srv0": {
11
+ "listen": [
12
+ ":443"
13
+ ],
14
+ "routes": [
15
+ {
16
+ "match": [
17
+ {
18
+ "host": [
19
+ "localhost"
20
+ ]
21
+ }
22
+ ],
23
+ "handle": [
24
+ {
25
+ "handler": "subroute",
26
+ "routes": [
27
+ {
28
+ "handle": [
29
+ {
30
+ "handler": "request_body",
31
+ "max_size": 1000000
32
+ }
33
+ ]
34
+ }
35
+ ]
36
+ }
37
+ ],
38
+ "terminal": true
39
+ }
40
+ ]
41
+ }
42
+ }
43
+ }
44
+ }
45
+}
\ No newline at end of file
modules/caddyhttp/requestbody/caddyfile.go
new
+51
@@ -0,0 +1,51 @@
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 requestbody
16
+
17
+import (
18
+ "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
19
+ "github.com/caddyserver/caddy/v2/modules/caddyhttp"
20
+ "github.com/dustin/go-humanize"
21
+)
22
+
23
+func init() {
24
+ httpcaddyfile.RegisterHandlerDirective("request_body", parseCaddyfile)
25
+}
26
+
27
+func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
28
+ rb := new(RequestBody)
29
+
30
+ for h.Next() {
31
+ // configuration should be in a block
32
+ for h.NextBlock(0) {
33
+ switch h.Val() {
34
+ case "max_size":
35
+ var sizeStr string
36
+ if !h.AllArgs(&sizeStr) {
37
+ return nil, h.ArgErr()
38
+ }
39
+ size, err := humanize.ParseBytes(sizeStr)
40
+ if err != nil {
41
+ return nil, h.Errf("parsing max_size: %v", err)
42
+ }
43
+ rb.MaxSize = int64(size)
44
+ default:
45
+ return nil, h.Errf("unrecognized servers option '%s'", h.Val())
46
+ }
47
+ }
48
+ }
49
+
50
+ return rb, nil
51
+}