1
Fork 0

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" "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) { func apiHandler(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if !ok { 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) { func TestParseBearerToken(t *testing.T) {
a := []struct{ a, b string }{ a := []struct{ a, b string }{
{"", ""}, {"", ""},