mirror of
https://github.com/jech/galene.git
synced 2024-12-22 07:15:47 +01:00
Implement parseContentType.
This commit is contained in:
parent
c4c7d0b60d
commit
e14eec86d3
2 changed files with 23 additions and 0 deletions
|
@ -9,6 +9,10 @@ import (
|
|||
"github.com/jech/galene/stats"
|
||||
)
|
||||
|
||||
func parseContentType(ctype string) string {
|
||||
return strings.Trim(strings.Split(ctype, ";")[0], " ")
|
||||
}
|
||||
|
||||
func apiHandler(w http.ResponseWriter, r *http.Request) {
|
||||
username, password, ok := r.BasicAuth()
|
||||
if !ok {
|
||||
|
|
|
@ -124,6 +124,25 @@ func TestParseSplit(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestParseContentType(t *testing.T) {
|
||||
a := []struct{ a, b string }{
|
||||
{"", ""},
|
||||
{"text/plain", "text/plain"},
|
||||
{"text/plain;charset=utf-8", "text/plain"},
|
||||
{"text/plain; charset=utf-8", "text/plain"},
|
||||
{"text/plain ; charset=utf-8", "text/plain"},
|
||||
}
|
||||
|
||||
for _, ab := range a {
|
||||
b := parseContentType(ab.a)
|
||||
if b != ab.b {
|
||||
t.Errorf("Content type %v, got %v, expected %v",
|
||||
ab.a, b, ab.b,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseBearerToken(t *testing.T) {
|
||||
a := []struct{ a, b string }{
|
||||
{"", ""},
|
||||
|
|
Loading…
Reference in a new issue