Permalink
Browse files

only set binary content-type if it's the default

  • Loading branch information...
mythz committed Feb 3, 2019
1 parent 6427ca0 commit 45a9c96168e802a0088fa04ef192e6930b7a2d8f
Showing with 6 additions and 4 deletions.
  1. +6 −4 src/ServiceStack/HttpResponseExtensionsInternal.cs
@@ -76,7 +76,6 @@ public static async Task<bool> WriteToOutputStreamAsync(IResponse response, obje
(bodySuffix?.Length).GetValueOrDefault();

response.SetContentLength(len);
response.ContentType = MimeTypes.Binary;

if (bodyPrefix != null) await response.OutputStream.WriteAsync(bodyPrefix, token);
await response.OutputStream.WriteAsync(bytes, token);
@@ -216,6 +215,7 @@ public static async Task<bool> WriteToResponse(this IResponse response, object r
response.Dto = result;
}

var config = HostContext.Config;
if (!response.HasStarted)
{
/* Mono Error: Exception: Method not found: 'System.Web.HttpResponse.get_Headers' */
@@ -250,21 +250,23 @@ public static async Task<bool> WriteToResponse(this IResponse response, object r
//Do not override if another has been set
if (response.ContentType == null || response.ContentType == MimeTypes.Html)
{
response.ContentType = defaultContentType;
response.ContentType = defaultContentType == (config.DefaultContentType ?? MimeTypes.Html) && result is byte[]
? MimeTypes.Binary
: defaultContentType;
}
if (bodyPrefix != null && response.ContentType.IndexOf(MimeTypes.Json, StringComparison.OrdinalIgnoreCase) >= 0)
{
response.ContentType = MimeTypes.JavaScript;
}

if (HostContext.Config.AppendUtf8CharsetOnContentTypes.Contains(response.ContentType))
if (config.AppendUtf8CharsetOnContentTypes.Contains(response.ContentType))
{
response.ContentType += ContentFormat.Utf8Suffix;
}
}

using (resultScope)
using (HostContext.Config.AllowJsConfig ? JsConfig.CreateScope(request.QueryString[Keywords.JsConfig]) : null)
using (config.AllowJsConfig ? JsConfig.CreateScope(request.QueryString[Keywords.JsConfig]) : null)
{
if (WriteToOutputStream(response, result, bodyPrefix, bodySuffix))
{

0 comments on commit 45a9c96

Please sign in to comment.