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 caddyhttp |
| 16 | |
| 17 | import ( |
| 18 | "net/http" |
| 19 | |
| 20 | "github.com/dunglas/httpsfv" |
| 21 | ) |
| 22 | |
| 23 | // incrementalHeader is the HTTP field with which a sender asks intermediaries |
| 24 | // to start forwarding a message before it has been received in full. |
| 25 | // See RFC 10036: https://www.rfc-editor.org/rfc/rfc10036.html |
| 26 | const incrementalHeader = "Incremental" |
| 27 | |
| 28 | // IsIncremental returns true if hdr requests incremental forwarding of the |
| 29 | // message it belongs to. The field applies to a single message, so a |
| 30 | // request and its response have to carry it independently. |
| 31 | func IsIncremental(hdr http.Header) bool { |
| 32 | vals := hdr.Values(incrementalHeader) |
| 33 | if len(vals) == 0 { |
| 34 | return false |
| 35 | } |
| 36 | |
| 37 | // every sender serializes true this way, and parsing it costs |
| 38 | // ~3x more time and two allocations |
| 39 | if len(vals) == 1 && vals[0] == "?1" { |
| 40 | return true |
| 41 | } |
| 42 | |
| 43 | item, err := httpsfv.UnmarshalItem(vals) |
| 44 | if err != nil { |
| 45 | return false |
| 46 | } |
| 47 | |
| 48 | // only a Boolean is valid; any other type is ignored, as are |
| 49 | // parameters we don't know about |
| 50 | b, ok := item.Value.(bool) |
| 51 | |
| 52 | return ok && b |
| 53 | } |