support basic authentication

This commit is contained in:
aler9
2020-06-14 18:34:36 +02:00
parent c06d302979
commit 2eddb95cab
7 changed files with 346 additions and 198 deletions

View File

@@ -3,6 +3,7 @@ package gortsplib
import (
"fmt"
"regexp"
"sort"
"strings"
)
@@ -40,3 +41,22 @@ func ReadHeaderAuth(in string) (*HeaderAuth, error) {
return ha, nil
}
// Write encodes an Authenticate or a WWW-Authenticate header.
func (ha *HeaderAuth) Write() string {
ret := ha.Prefix + " "
var sortedKeys []string
for key := range ha.Values {
sortedKeys = append(sortedKeys, key)
}
sort.Strings(sortedKeys)
var tmp []string
for _, key := range sortedKeys {
tmp = append(tmp, key+"=\""+ha.Values[key]+"\"")
}
ret += strings.Join(tmp, ", ")
return ret
}