allow headers with zero or multiple spaces between key and value

This commit is contained in:
aler9
2020-06-14 17:29:40 +02:00
parent 37bd9a1b98
commit c06d302979
9 changed files with 99 additions and 73 deletions

View File

@@ -14,7 +14,7 @@ const (
_MAX_HEADER_VALUE_LENGTH = 1024
)
func normalizeHeaderKey(in string) string {
func headerKeyNormalize(in string) string {
switch strings.ToLower(in) {
case "rtp-info":
return "RTP-INFO"
@@ -31,7 +31,7 @@ func normalizeHeaderKey(in string) string {
// Header is a RTSP reader, present in both Requests and Responses.
type Header map[string][]string
func readHeader(rb *bufio.Reader) (Header, error) {
func headerRead(rb *bufio.Reader) (Header, error) {
h := make(Header)
for {
@@ -59,12 +59,21 @@ func readHeader(rb *bufio.Reader) (Header, error) {
return nil, err
}
key += string(byts[:len(byts)-1])
key = normalizeHeaderKey(key)
key = headerKeyNormalize(key)
err = readByteEqual(rb, ' ')
if err != nil {
return nil, err
// https://tools.ietf.org/html/rfc2616
// The field value MAY be preceded by any amount of spaces
for {
byt, err := rb.ReadByte()
if err != nil {
return nil, err
}
if byt != ' ' {
break
}
}
rb.UnreadByte()
byts, err = readBytesLimited(rb, '\r', _MAX_HEADER_VALUE_LENGTH)
if err != nil {