fix linkHeader restrictly

pull/28/head
Yasuhiro Matsumoto 2017-04-19 17:48:42 +09:00
parent 3a90b559e1
commit 00bd1f0aba
1 changed files with 32 additions and 7 deletions

View File

@ -37,19 +37,44 @@ type page struct {
func linkHeader(h http.Header, rel string) []string { func linkHeader(h http.Header, rel string) []string {
var links []string var links []string
for _, v := range h["Link"] { for _, v := range h["Link"] {
parts := strings.Split(v, ";") var p string
for _, p := range parts { for len(v) > 0 {
p = strings.TrimSpace(p) i := strings.Index(v, ";")
if !strings.HasPrefix(p, "rel=") { if i < 0 {
continue break
} }
e := i
i++
for i < len(v) {
if v[i] != ' ' {
break
}
i++
}
p = strings.TrimSpace(v[i:])
if !strings.HasPrefix(p, "rel=") {
break
}
i += 4
pos := strings.Index(p[4:], `,`) pos := strings.Index(p[4:], `,`)
if pos > 0 { if pos > 0 {
p = p[4 : 4+pos] p = p[4 : 4+pos]
i += pos
} else {
p = p[4:]
i = len(v) - 1
} }
if v := strings.Trim(p, `"`); v == rel { if k := strings.Trim(p, `"`); k == rel {
links = append(links, strings.Trim(parts[0], "<>")) links = append(links, strings.Trim(v[:e], "<>"))
} }
i++
for i < len(v) {
if v[i] != ' ' {
break
}
i++
}
v = v[i:]
} }
} }
return links return links