This repository was archived by the owner on Jan 24, 2021. It is now read-only.
File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,20 @@ public void Should_set_content_type_to_text_html_when_implicitly_cast_from_strin
154
154
response . ContentType . ShouldEqual ( "text/html" ) ;
155
155
}
156
156
157
+ [ Fact ]
158
+ public void Should_overwrite_content_type_from_headers ( )
159
+ {
160
+ // Given
161
+ const string value = "test value" ;
162
+ Response response = value ;
163
+
164
+ // When
165
+ response . Headers . Add ( "contenT-typE" , "application/json" ) ;
166
+
167
+ // Then
168
+ response . ContentType . ShouldEqual ( "application/json" ) ;
169
+ }
170
+
157
171
[ Fact ]
158
172
public void Should_set_a_cookie_with_name_and_value ( )
159
173
{
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ namespace Nancy
3
3
using System ;
4
4
using System . Collections . Generic ;
5
5
using System . IO ;
6
+ using System . Linq ;
6
7
using System . Threading . Tasks ;
7
8
8
9
using Cookies ;
@@ -19,14 +20,16 @@ public class Response: IDisposable
19
20
/// </summary>
20
21
public static Action < Stream > NoBody = s => { } ;
21
22
23
+ private string contentType ;
24
+
22
25
/// <summary>
23
26
/// Initializes a new instance of the <see cref="Response"/> class.
24
27
/// </summary>
25
28
public Response ( )
26
29
{
27
30
this . Contents = NoBody ;
28
31
this . ContentType = "text/html" ;
29
- this . Headers = new Dictionary < string , string > ( ) ;
32
+ this . Headers = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) ;
30
33
this . StatusCode = HttpStatusCode . OK ;
31
34
this . Cookies = new List < INancyCookie > ( 2 ) ;
32
35
}
@@ -36,7 +39,11 @@ public Response()
36
39
/// </summary>
37
40
/// <value>The type of the content.</value>
38
41
/// <remarks>The default value is <c>text/html</c>.</remarks>
39
- public string ContentType { get ; set ; }
42
+ public string ContentType
43
+ {
44
+ get { return Headers . ContainsKey ( "content-type" ) ? Headers [ "content-type" ] : this . contentType ; }
45
+ set { this . contentType = value ; }
46
+ }
40
47
41
48
/// <summary>
42
49
/// Gets the delegate that will render contents to the response stream.
You can’t perform that action at this time.
0 commit comments