Skip to content

Commit

Permalink
fix #15
Browse files Browse the repository at this point in the history
  • Loading branch information
lvermeulen committed Apr 12, 2019
1 parent 479b139 commit 6efae75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Flurl.Http.Xml.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.14
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.156
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F2114366-0322-434F-91D3-A25939F0CFA7}"
ProjectSection(SolutionItems) = preProject
Expand Down
4 changes: 2 additions & 2 deletions src/Flurl.Http.Xml/FlurlRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ private static string GetMediaType(this IHttpSettingsContainer request)
.Select(x => x.Trim())
.ToList();

return mediaTypes.First(x => x.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0)
?? mediaTypes.First();
return mediaTypes.FirstOrDefault(x => x.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0)
?? mediaTypes.FirstOrDefault();
}

/// <summary>
Expand Down
10 changes: 6 additions & 4 deletions src/Flurl.Http.Xml/HttpResponseMessageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ private static string GetMediaType(HttpRequestMessage request)
if (request.Headers.Accept.Any())
{
// return media type of first accepted media type containing "xml", else of first accepted media type
var acceptHeader = request.Headers.Accept.First(x => x.MediaType.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0)
?? request.Headers.Accept.First();

return acceptHeader.MediaType;
var acceptHeader = request.Headers.Accept.FirstOrDefault(x => x.MediaType.IndexOf("xml", StringComparison.OrdinalIgnoreCase) >= 0)
?? request.Headers.Accept.FirstOrDefault();
if (acceptHeader != null)
{
return acceptHeader.MediaType;
}
}

// no accepted media type present, return default
Expand Down

0 comments on commit 6efae75

Please sign in to comment.