Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryoussefm <youssefm@microsoft.com>2012-10-10 01:51:24 +0400
committeryoussefm <youssefm@microsoft.com>2012-10-10 03:34:26 +0400
commit1b5b1c247f12889f4bd9238723d80ad02ac457a1 (patch)
tree06f23b34b0f439cf86e2fd6a8a08d478e8538a7d
parent5474a5581e640a62ca050918fded196603410402 (diff)
[OData] Ensure charset gets set in the response headers
-rw-r--r--src/System.Web.Http.OData/OData/Formatter/ODataMediaTypeFormatter.cs1
-rw-r--r--test/System.Web.Http.OData.Test/OData/Formatter/ODataMediaTypeFormatterTests.cs17
2 files changed, 18 insertions, 0 deletions
diff --git a/src/System.Web.Http.OData/OData/Formatter/ODataMediaTypeFormatter.cs b/src/System.Web.Http.OData/OData/Formatter/ODataMediaTypeFormatter.cs
index f4e1be4b..47c3ffd6 100644
--- a/src/System.Web.Http.OData/OData/Formatter/ODataMediaTypeFormatter.cs
+++ b/src/System.Web.Http.OData/OData/Formatter/ODataMediaTypeFormatter.cs
@@ -140,6 +140,7 @@ namespace System.Web.Http.OData.Formatter
if (String.Equals("Content-Type", pair.Key, StringComparison.OrdinalIgnoreCase))
{
headers.ContentType = MediaTypeHeaderValue.Parse(pair.Value);
+ headers.ContentType.CharSet = Encoding.UTF8.WebName;
}
else
{
diff --git a/test/System.Web.Http.OData.Test/OData/Formatter/ODataMediaTypeFormatterTests.cs b/test/System.Web.Http.OData.Test/OData/Formatter/ODataMediaTypeFormatterTests.cs
index 51158bb2..fffe701f 100644
--- a/test/System.Web.Http.OData.Test/OData/Formatter/ODataMediaTypeFormatterTests.cs
+++ b/test/System.Web.Http.OData.Test/OData/Formatter/ODataMediaTypeFormatterTests.cs
@@ -96,6 +96,23 @@ namespace System.Web.Http.OData.Formatter
Assert.Equal(headervalues, new string[] { expectedDataServiceVersion + ";" });
}
+ [Theory]
+ [InlineData("application/atom+xml")]
+ [InlineData("application/json")]
+ [InlineData("application/xml")]
+ public void SetDefaultContentHeaders_SetsRightContentTypeCharSet(string mediaType)
+ {
+ HttpRequestMessage request = new HttpRequestMessage();
+ HttpContentHeaders contentHeaders = new StringContent("").Headers;
+
+ new ODataMediaTypeFormatter()
+ .GetPerRequestFormatterInstance(typeof(int), request, MediaTypeHeaderValue.Parse(mediaType))
+ .SetDefaultContentHeaders(typeof(int), contentHeaders, MediaTypeHeaderValue.Parse(mediaType));
+
+ Assert.NotNull(contentHeaders.ContentType.CharSet);
+ Assert.Equal("utf-8", contentHeaders.ContentType.CharSet);
+ }
+
[Fact]
public void TryGetInnerTypeForDelta_ChangesRefToGenericParameter_ForDeltas()
{