Skip to content

Commit 8408326

Browse files
Matt Masonmathewc
authored andcommitted
Fix parsing of content-disposition header
1 parent 2ad0ad1 commit 8408326

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/WebJobs.Script/Binding/HttpBinding.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,11 @@ internal static void AddResponseHeader(HttpResponseMessage response, KeyValuePai
302302
}
303303
break;
304304
case "content-disposition":
305-
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue(header.Value.ToString());
305+
ContentDispositionHeaderValue contentDisposition = null;
306+
if (ContentDispositionHeaderValue.TryParse(header.Value.ToString(), out contentDisposition))
307+
{
308+
response.Content.Headers.ContentDisposition = contentDisposition;
309+
}
306310
break;
307311
case "content-encoding":
308312
case "content-language":

test/WebJobs.Script.Tests/Binding/HttpBindingTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ public void AddResponseHeader_ContentMD5_AddsExpectedHeader()
4141
Assert.Equal(base64, Convert.ToBase64String(response.Content.Headers.ContentMD5));
4242
}
4343

44+
[Fact]
45+
public void AddResponseHeader_ContentDisposition_AddsExpectedHeader()
46+
{
47+
HttpResponseMessage response = new HttpResponseMessage()
48+
{
49+
Content = new StringContent("Test")
50+
};
51+
var cd = "attachment; filename=\"test.txt\"";
52+
var header = new KeyValuePair<string, object>("content-disposition", cd);
53+
HttpBinding.AddResponseHeader(response, header);
54+
Assert.Equal(cd, response.Content.Headers.ContentDisposition.ToString());
55+
}
56+
4457
[Fact]
4558
public void ParseResponseObject_ReturnsExpectedResult()
4659
{

0 commit comments

Comments
 (0)