forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_test.go
114 lines (109 loc) · 2.49 KB
/
header_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package gortsplib
import (
"bufio"
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
var casesHeader = []struct {
name string
dec []byte
enc []byte
header Header
}{
{
"single",
[]byte("Proxy-Require: gzipped-messages\r\n" +
"Require: implicit-play\r\n" +
"\r\n"),
[]byte("Proxy-Require: gzipped-messages\r\n" +
"Require: implicit-play\r\n" +
"\r\n"),
Header{
"Require": HeaderValue{"implicit-play"},
"Proxy-Require": HeaderValue{"gzipped-messages"},
},
},
{
"multiple",
[]byte("WWW-Authenticate: Digest realm=\"4419b63f5e51\", nonce=\"8b84a3b789283a8bea8da7fa7d41f08b\", stale=\"FALSE\"\r\n" +
"WWW-Authenticate: Basic realm=\"4419b63f5e51\"\r\n" +
"\r\n"),
[]byte("WWW-Authenticate: Digest realm=\"4419b63f5e51\", nonce=\"8b84a3b789283a8bea8da7fa7d41f08b\", stale=\"FALSE\"\r\n" +
"WWW-Authenticate: Basic realm=\"4419b63f5e51\"\r\n" +
"\r\n"),
Header{
"WWW-Authenticate": HeaderValue{
`Digest realm="4419b63f5e51", nonce="8b84a3b789283a8bea8da7fa7d41f08b", stale="FALSE"`,
`Basic realm="4419b63f5e51"`,
},
},
},
{
"without space",
[]byte("CSeq:2\r\n" +
"\r\n"),
[]byte("CSeq: 2\r\n" +
"\r\n"),
Header{
"CSeq": HeaderValue{"2"},
},
},
{
"with multiple spaces",
[]byte("CSeq: 2\r\n" +
"\r\n"),
[]byte("CSeq: 2\r\n" +
"\r\n"),
Header{
"CSeq": HeaderValue{"2"},
},
},
{
"normalized keys, standard",
[]byte("Content-type: testing\r\n" +
"Content-length: value\r\n" +
"\r\n"),
[]byte("Content-Length: value\r\n" +
"Content-Type: testing\r\n" +
"\r\n"),
Header{
"Content-Length": HeaderValue{"value"},
"Content-Type": HeaderValue{"testing"},
},
},
{
"normalized keys, non-standard",
[]byte("Www-Authenticate: value\r\n" +
"Cseq: value\r\n" +
"\r\n"),
[]byte("CSeq: value\r\n" +
"WWW-Authenticate: value\r\n" +
"\r\n"),
Header{
"CSeq": HeaderValue{"value"},
"WWW-Authenticate": HeaderValue{"value"},
},
},
}
func TestHeaderRead(t *testing.T) {
for _, c := range casesHeader {
t.Run(c.name, func(t *testing.T) {
req, err := headerRead(bufio.NewReader(bytes.NewBuffer(c.dec)))
require.NoError(t, err)
require.Equal(t, c.header, req)
})
}
}
func TestHeaderWrite(t *testing.T) {
for _, c := range casesHeader {
t.Run(c.name, func(t *testing.T) {
var buf bytes.Buffer
bw := bufio.NewWriter(&buf)
err := c.header.write(bw)
require.NoError(t, err)
bw.Flush()
require.Equal(t, c.enc, buf.Bytes())
})
}
}