Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/Functions/Functions.Tests/ClientContractTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ public async Task Invoke_ShouldPreferOptionHeadersOverDynamicHeaders()
this.HeaderOf("x-shared").Should().Be("from-options");
}

[TestMethod]
public async Task Invoke_ShouldSendOptionContentType_GivenLowercaseHeaderName()
{
this.RespondWith(200, "ok");
await this.client.Invoke(FunctionName, options: new InvokeFunctionOptions
{
Headers = new Dictionary<string, string> { { "content-type", "text/plain" } }
});
this.HeaderOf("Content-Type").Should().Be("text/plain");
}

[TestMethod]
public async Task Invoke_ShouldThrowFunctionsException_GivenServerError()
{
Expand Down
16 changes: 11 additions & 5 deletions packages/Functions/Functions/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,20 @@ private static Uri BuildUri(string url)

private static HttpRequestMessage BuildRequestMessage(InvokeFunctionOptions options, Uri uri)
{
var request = new HttpRequestMessage(options.HttpMethod, uri)
{
Content = new StringContent(JsonSerializer.Serialize(options.Body, SerializerOptions), Encoding.UTF8, "application/json")
};
var content = new StringContent(JsonSerializer.Serialize(options.Body, SerializerOptions), Encoding.UTF8, "application/json");
var request = new HttpRequestMessage(options.HttpMethod, uri) { Content = content };

foreach (var kvp in options.Headers)
{
request.Headers.TryAddWithoutValidation(kvp.Key, kvp.Value);
if (string.Equals(kvp.Key, "Content-Type", StringComparison.OrdinalIgnoreCase))
{
content.Headers.Remove("Content-Type");
content.Headers.TryAddWithoutValidation("Content-Type", kvp.Value);
}
else
{
request.Headers.TryAddWithoutValidation(kvp.Key, kvp.Value);
}
}

return request;
Expand Down
Loading