1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 18:25:58 +01:00

Implement parseContentType.

This commit is contained in:
Juliusz Chroboczek 2024-04-09 15:30:11 +02:00
parent c4c7d0b60d
commit e14eec86d3
2 changed files with 23 additions and 0 deletions

View file

@ -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 {

View file

@ -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 }{
{"", ""},