41 lines
837 B
Go
41 lines
837 B
Go
![]() |
package zocket
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"strings"
|
||
|
"udico.de/util/log"
|
||
|
)
|
||
|
|
||
|
type zocketHeader struct {
|
||
|
http.Header
|
||
|
}
|
||
|
|
||
|
// Has returns true, if one entry of the given key has the exact value.
|
||
|
func (f zocketHeader) Has(key, value string) bool {
|
||
|
log.TRACE.To(logger).If(func(msg log.Fn) {
|
||
|
msg("Has(%v, %v)? Dumping", key, value)
|
||
|
for k, v := range f.Values(key) {
|
||
|
msg(" [%v]: %v", k, v)
|
||
|
}
|
||
|
})
|
||
|
for _, v := range f.Values(key) {
|
||
|
if v == value {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
// Contains returns true, if at least one entry of the given key contains the value as part of a comma separated list.
|
||
|
func (f zocketHeader) Contains(key, value string) bool {
|
||
|
for _, v := range f.Values(key) {
|
||
|
for _, w := range strings.Split(v, ",") {
|
||
|
ws := strings.TrimSpace(w)
|
||
|
if ws == value {
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return false
|
||
|
}
|