@@ -62,34 +62,34 @@ var _ = Describe("ResponseWriter tests", func() {
62
62
Expect ("application/json" ).To (Equal (resp .Header ().Get ("Content-Type" )))
63
63
proxyResp , err := resp .GetProxyResponse ()
64
64
Expect (err ).To (BeNil ())
65
- Expect (1 ).To (Equal (len (proxyResp .Headers )))
66
- Expect ("application/json" ).To (Equal (proxyResp .Headers ["Content-Type" ]))
65
+ Expect (1 ).To (Equal (len (proxyResp .MultiValueHeaders )))
66
+ Expect ("application/json" ).To (Equal (proxyResp .MultiValueHeaders ["Content-Type" ][ 0 ]))
67
67
Expect (xmlBodyContent ).To (Equal (proxyResp .Body ))
68
68
})
69
69
70
- It ("Sets the conte type to text/xml given the body" , func () {
70
+ It ("Sets the content type to text/xml given the body" , func () {
71
71
resp := NewProxyResponseWriter ()
72
72
resp .Write ([]byte (xmlBodyContent ))
73
73
74
74
Expect ("" ).ToNot (Equal (resp .Header ().Get ("Content-Type" )))
75
75
Expect (true ).To (Equal (strings .HasPrefix (resp .Header ().Get ("Content-Type" ), "text/xml;" )))
76
76
proxyResp , err := resp .GetProxyResponse ()
77
77
Expect (err ).To (BeNil ())
78
- Expect (1 ).To (Equal (len (proxyResp .Headers )))
79
- Expect (true ).To (Equal (strings .HasPrefix (proxyResp .Headers ["Content-Type" ], "text/xml;" )))
78
+ Expect (1 ).To (Equal (len (proxyResp .MultiValueHeaders )))
79
+ Expect (true ).To (Equal (strings .HasPrefix (proxyResp .MultiValueHeaders ["Content-Type" ][ 0 ], "text/xml;" )))
80
80
Expect (xmlBodyContent ).To (Equal (proxyResp .Body ))
81
81
})
82
82
83
- It ("Sets the conte type to text/html given the body" , func () {
83
+ It ("Sets the content type to text/html given the body" , func () {
84
84
resp := NewProxyResponseWriter ()
85
85
resp .Write ([]byte (htmlBodyContent ))
86
86
87
87
Expect ("" ).ToNot (Equal (resp .Header ().Get ("Content-Type" )))
88
88
Expect (true ).To (Equal (strings .HasPrefix (resp .Header ().Get ("Content-Type" ), "text/html;" )))
89
89
proxyResp , err := resp .GetProxyResponse ()
90
90
Expect (err ).To (BeNil ())
91
- Expect (1 ).To (Equal (len (proxyResp .Headers )))
92
- Expect (true ).To (Equal (strings .HasPrefix (proxyResp .Headers ["Content-Type" ], "text/html;" )))
91
+ Expect (1 ).To (Equal (len (proxyResp .MultiValueHeaders )))
92
+ Expect (true ).To (Equal (strings .HasPrefix (proxyResp .MultiValueHeaders ["Content-Type" ][ 0 ], "text/html;" )))
93
93
Expect (htmlBodyContent ).To (Equal (proxyResp .Body ))
94
94
})
95
95
})
@@ -114,8 +114,8 @@ var _ = Describe("ResponseWriter tests", func() {
114
114
115
115
Expect ("hello" ).To (Equal (proxyResponse .Body ))
116
116
Expect (http .StatusOK ).To (Equal (proxyResponse .StatusCode ))
117
- Expect (1 ).To (Equal (len (proxyResponse .Headers )))
118
- Expect (true ).To (Equal (strings .HasPrefix (proxyResponse .Headers ["Content-Type" ], "text/plain" )))
117
+ Expect (1 ).To (Equal (len (proxyResponse .MultiValueHeaders )))
118
+ Expect (true ).To (Equal (strings .HasPrefix (proxyResponse .MultiValueHeaders ["Content-Type" ][ 0 ], "text/plain" )))
119
119
Expect (proxyResponse .IsBase64Encoded ).To (BeFalse ())
120
120
})
121
121
@@ -138,9 +138,43 @@ var _ = Describe("ResponseWriter tests", func() {
138
138
Expect (base64 .StdEncoding .EncodedLen (len (binaryBody ))).To (Equal (len (proxyResponse .Body )))
139
139
140
140
Expect (base64 .StdEncoding .EncodeToString (binaryBody )).To (Equal (proxyResponse .Body ))
141
- Expect (1 ).To (Equal (len (proxyResponse .Headers )))
142
- Expect ("application/octet-stream" ).To (Equal (proxyResponse .Headers ["Content-Type" ]))
141
+ Expect (1 ).To (Equal (len (proxyResponse .MultiValueHeaders )))
142
+ Expect ("application/octet-stream" ).To (Equal (proxyResponse .MultiValueHeaders ["Content-Type" ][ 0 ]))
143
143
Expect (http .StatusAccepted ).To (Equal (proxyResponse .StatusCode ))
144
144
})
145
145
})
146
+
147
+ Context ("Handle multi-value headers" , func () {
148
+
149
+ It ("Writes single-value headers correctly" , func () {
150
+ response := NewProxyResponseWriter ()
151
+ response .Header ().Add ("Content-Type" , "application/json" )
152
+ response .Write ([]byte ("hello" ))
153
+ proxyResponse , err := response .GetProxyResponse ()
154
+ Expect (err ).To (BeNil ())
155
+
156
+ // Headers are not written to `Headers` field
157
+ Expect (0 ).To (Equal (len (proxyResponse .Headers )))
158
+ Expect (1 ).To (Equal (len (proxyResponse .MultiValueHeaders ["Content-Type" ])))
159
+ Expect ("application/json" ).To (Equal (proxyResponse .MultiValueHeaders ["Content-Type" ][0 ]))
160
+ })
161
+
162
+ It ("Writes multi-value headers correctly" , func () {
163
+ response := NewProxyResponseWriter ()
164
+ response .Header ().Add ("Set-Cookie" , "csrftoken=foobar" )
165
+ response .Header ().Add ("Set-Cookie" , "session_id=barfoo" )
166
+ response .Write ([]byte ("hello" ))
167
+ proxyResponse , err := response .GetProxyResponse ()
168
+ Expect (err ).To (BeNil ())
169
+
170
+ // Headers are not written to `Headers` field
171
+ Expect (0 ).To (Equal (len (proxyResponse .Headers )))
172
+
173
+ // There are two headers here because Content-Type is always written implicitly
174
+ Expect (2 ).To (Equal (len (proxyResponse .MultiValueHeaders ["Set-Cookie" ])))
175
+ Expect ("csrftoken=foobar" ).To (Equal (proxyResponse .MultiValueHeaders ["Set-Cookie" ][0 ]))
176
+ Expect ("session_id=barfoo" ).To (Equal (proxyResponse .MultiValueHeaders ["Set-Cookie" ][1 ]))
177
+ })
178
+ })
179
+
146
180
})
0 commit comments