Skip to content

Commit 82ce506

Browse files
committed
third_party/httpcache: add copy of parts of httpcache
1 parent 0da52d1 commit 82ce506

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

third_party/httpcache/LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright © 2012 Greg Jones ([email protected])
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

third_party/httpcache/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
httpcache is a copy of <https://github.com/gregjones/httpcache>
2+
with only the cache control header parsing logic.

third_party/httpcache/httpcache.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package httpcache
2+
3+
import (
4+
"net/http"
5+
"strings"
6+
)
7+
8+
type cacheControl map[string]string
9+
10+
func parseCacheControl(headers http.Header) cacheControl {
11+
cc := cacheControl{}
12+
ccHeader := headers.Get("Cache-Control")
13+
for _, part := range strings.Split(ccHeader, ",") {
14+
part = strings.Trim(part, " ")
15+
if part == "" {
16+
continue
17+
}
18+
if strings.ContainsRune(part, '=') {
19+
keyval := strings.Split(part, "=")
20+
cc[strings.Trim(keyval[0], " ")] = strings.Trim(keyval[1], ",")
21+
} else {
22+
cc[part] = ""
23+
}
24+
}
25+
return cc
26+
}

0 commit comments

Comments
 (0)