mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-26 05:09:16 +01:00
42 lines
874 B
Go
42 lines
874 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
func readBoolParam(r *http.Request, defaultValue bool, names ...string) bool {
|
|
value := strings.ToLower(readParam(r, names...))
|
|
if value == "" {
|
|
return defaultValue
|
|
}
|
|
return value == "1" || value == "yes" || value == "true"
|
|
}
|
|
|
|
func readParam(r *http.Request, names ...string) string {
|
|
value := readHeaderParam(r, names...)
|
|
if value != "" {
|
|
return value
|
|
}
|
|
return readQueryParam(r, names...)
|
|
}
|
|
|
|
func readHeaderParam(r *http.Request, names ...string) string {
|
|
for _, name := range names {
|
|
value := r.Header.Get(name)
|
|
if value != "" {
|
|
return strings.TrimSpace(value)
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func readQueryParam(r *http.Request, names ...string) string {
|
|
for _, name := range names {
|
|
value := r.URL.Query().Get(strings.ToLower(name))
|
|
if value != "" {
|
|
return strings.TrimSpace(value)
|
|
}
|
|
}
|
|
return ""
|
|
}
|