-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Use strongly typed MediaTypeHeaderValue for content type in action resul... #2450
Conversation
/// </summary> | ||
/// <param name="fileContents">The bytes that represent the file contents.</param> | ||
public FileContentResult([NotNull] byte[] fileContents) | ||
: base(contentType: null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we compare to MVC5, content type was always required:
http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Mvc/FileResult.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be like a compatiblity bug fix - should have been dealt with as a separate PR. (Its fine to leave this here for this one, but something to keep in mind in general ).
ping |
@@ -26,17 +29,34 @@ public class ContentResult : ActionResult | |||
{ | |||
var response = context.HttpContext.Response; | |||
|
|||
// Encoding property on MediaTypeHeaderValue does not return the exact encoding instance that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to this. If using the encoding set in ContentType
is incorrect, we have an issue with the way MediaTypeHeaderValue.Encoding
behaves. cc @Tratcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm planning to remove MediaTypeHeaderValue.Encoding, it's causing confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pranavkm is that a happy or sad panda?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't 🐼 always sad?
258f314
to
f17970b
Compare
Updated. /cc: @pranavkm |
Are we sure we want to do this? |
@davidfowl what's the concern? |
f17970b
to
64b77ea
Compare
Updated /cc: @pranavkm @harshgMSFT @rynowak In the newest iteration, I added a |
} | ||
else | ||
{ | ||
contentTypeHeader = new MediaTypeHeaderValue(ContentType); | ||
if(string.IsNullOrEmpty(contentTypeHeader.Charset)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this not go away?
e103bb5
to
d3055f7
Compare
|
||
public string ContentType { get; set; } | ||
public MediaTypeHeaderValue ContentType { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're touching these files, could you add docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bump.
⌚ mostly done. There's a couple of un-addressed items. Would also like @rynowak to have a look at this? |
Updated. /cc: @pranavkm @rynowak @ajaybhargavb |
9a0d0d4
to
ba3b3e9
Compare
|
||
public Encoding ContentEncoding { get; set; } | ||
public string Content { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs for this.
|
|
||
public Encoding ContentEncoding { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we removing this because ContentEncoding is included in MediaTypeHeaderValue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, right...(as a side note...this property name is just confusing...as per Http this would represent the encoding like gzip, deflate)..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
⌚ |
@@ -46,7 +47,7 @@ public FilePathResult([NotNull] string fileName) | |||
/// <param name="fileName">The path to the file. The path must be an absolute | |||
/// path. Relative and virtual paths are not supported.</param> | |||
/// <param name="contentType">The Content-Type header of the response.</param> | |||
public FilePathResult([NotNull] string fileName, string contentType) | |||
public FilePathResult([NotNull] string fileName, MediaTypeHeaderValue contentType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NotNull]
⌚ |
ba3b3e9
to
29b8c3d
Compare
|
||
actionContext.HttpContext.Response.ContentType = contentType; | ||
var wrappedStream = new StreamWrapper(actionContext.HttpContext.Response.Body); | ||
var encoding = Encodings.UTF8EncodingWithoutBOM; | ||
using (var writer = new StreamWriter(wrappedStream, encoding, BufferSize, leaveOpen: true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, filed: #2496
Updated as per our discussion. /cc: @pranavkm @rynowak @harshgMSFT |
|
Sorry for commenting on the commit rather than on PR. |
29b8c3d
to
7e62325
Compare
...ts.
@rynowak @pranavkm