Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Use strongly typed MediaTypeHeaderValue for content type in action resul... #2450

Merged
merged 1 commit into from
May 4, 2015

Conversation

kichalla
Copy link
Member

@ghost ghost added the cla-already-signed label Apr 24, 2015
/// </summary>
/// <param name="fileContents">The bytes that represent the file contents.</param>
public FileContentResult([NotNull] byte[] fileContents)
: base(contentType: null)
Copy link
Member Author

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

Copy link
Contributor

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 ).

@kichalla
Copy link
Member Author

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
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐼

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't 🐼 always sad?

@kichalla kichalla force-pushed the kiran/standardize-mediatypeheadervalue branch 3 times, most recently from 258f314 to f17970b Compare April 29, 2015 00:13
@kichalla
Copy link
Member Author

Updated. /cc: @pranavkm

@davidfowl
Copy link
Member

Are we sure we want to do this?

@pranavkm
Copy link
Contributor

@davidfowl what's the concern?

@kichalla kichalla force-pushed the kiran/standardize-mediatypeheadervalue branch from f17970b to 64b77ea Compare April 29, 2015 16:58
@kichalla
Copy link
Member Author

Updated /cc: @pranavkm @harshgMSFT @rynowak

In the newest iteration, I added a ResponseEncodingWrapper which ignores the preamble of the original encoding(except the UTF16 little endian which we explicitly set to honor https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Common/Encodings.cs#L20)

}
else
{
contentTypeHeader = new MediaTypeHeaderValue(ContentType);
if(string.IsNullOrEmpty(contentTypeHeader.Charset))
Copy link
Contributor

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?

@kichalla kichalla force-pushed the kiran/standardize-mediatypeheadervalue branch from e103bb5 to d3055f7 Compare April 29, 2015 22:46

public string ContentType { get; set; }
public MediaTypeHeaderValue ContentType { get; set; }
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump.

@pranavkm
Copy link
Contributor

⌚ mostly done. There's a couple of un-addressed items. Would also like @rynowak to have a look at this?

@kichalla
Copy link
Member Author

Updated. /cc: @pranavkm @rynowak @ajaybhargavb

@kichalla kichalla force-pushed the kiran/standardize-mediatypeheadervalue branch from 9a0d0d4 to ba3b3e9 Compare May 1, 2015 00:27

public Encoding ContentEncoding { get; set; }
public string Content { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs for this.

@pranavkm
Copy link
Contributor

pranavkm commented May 1, 2015

:shipit:. Try and get @rynowak to look at this before you merge it in.


public Encoding ContentEncoding { get; set; }
Copy link
Contributor

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?

Copy link
Member Author

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)..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rynowak
Copy link
Member

rynowak commented May 4, 2015

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NotNull]

@harshgMSFT
Copy link
Contributor

@kichalla kichalla force-pushed the kiran/standardize-mediatypeheadervalue branch from ba3b3e9 to 29b8c3d Compare May 4, 2015 20:08

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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, filed: #2496

@kichalla
Copy link
Member Author

kichalla commented May 4, 2015

Updated as per our discussion. /cc: @pranavkm @rynowak @harshgMSFT

@rynowak
Copy link
Member

rynowak commented May 4, 2015

:shipit:

@harshgMSFT
Copy link
Contributor

Sorry for commenting on the commit rather than on PR. :shipit: after addressing the comments.

@kichalla kichalla force-pushed the kiran/standardize-mediatypeheadervalue branch from 29b8c3d to 7e62325 Compare May 4, 2015 21:07
@kichalla kichalla merged commit 7e62325 into dev May 4, 2015
@kichalla kichalla deleted the kiran/standardize-mediatypeheadervalue branch May 12, 2015 22:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants