Skip to content

Commit ab6cb74

Browse files
committed
Making sure content is not null when handling conneg
1 parent 841afb8 commit ab6cb74

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/WebJobs.Script/Binding/HttpBinding.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ private static HttpResponseMessage CreateResponse(HttpRequestMessage request, Ht
108108
{
109109
JToken contentType = null;
110110
MediaTypeHeaderValue mediaType = null;
111-
if ((headers?.TryGetValue("content-type", StringComparison.OrdinalIgnoreCase, out contentType) ?? false) &&
111+
if (content != null &&
112+
(headers?.TryGetValue("content-type", StringComparison.OrdinalIgnoreCase, out contentType) ?? false) &&
112113
MediaTypeHeaderValue.TryParse(contentType.Value<string>(), out mediaType))
113114
{
114115
MediaTypeFormatter writer = request.GetConfiguration()
@@ -156,6 +157,11 @@ private static HttpContent CreateResultContent(object content, string mediaType)
156157

157158
private static HttpResponseMessage CreateNegotiatedResponse(HttpRequestMessage request, HttpStatusCode statusCode, object content)
158159
{
160+
if (content == null)
161+
{
162+
return request.CreateResponse(statusCode);
163+
}
164+
159165
var configuration = request.GetConfiguration();
160166
IContentNegotiator negotiator = configuration.Services.GetContentNegotiator();
161167
var result = negotiator.Negotiate(content.GetType(), request, configuration.Formatters);

0 commit comments

Comments
 (0)