Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 01:00 UTC
| 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/dustin/go-humanize" |
| 19 | |
| 20 | "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile" |
| 21 | "github.com/caddyserver/caddy/v2/modules/caddyhttp" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | httpcaddyfile.RegisterHandlerDirective("request_body", parseCaddyfile) |
| 26 | } |
| 27 | |
| 28 | func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { |
| 29 | h.Next() // consume directive name |
| 30 | |
| 31 | rb := new(RequestBody) |
| 32 | |
| 33 | // configuration should be in a block |
| 34 | for h.NextBlock(0) { |
| 35 | switch h.Val() { |
| 36 | case "max_size": |
| 37 | var sizeStr string |
| 38 | if !h.AllArgs(&sizeStr) { |
| 39 | return nil, h.ArgErr() |
| 40 | } |
| 41 | size, err := humanize.ParseBytes(sizeStr) |
| 42 | if err != nil { |
| 43 | return nil, h.Errf("parsing max_size: %v", err) |
| 44 | } |
| 45 | rb.MaxSize = int64(size) |
| 46 | |
| 47 | case "set": |
| 48 | var setStr string |
| 49 | if !h.AllArgs(&setStr) { |
| 50 | return nil, h.ArgErr() |
| 51 | } |
| 52 | rb.Set = setStr |
| 53 | default: |
| 54 | return nil, h.Errf("unrecognized request_body subdirective '%s'", h.Val()) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return rb, nil |
| 59 | } |