Skip to content

Commit

Permalink
Override ContentType header when sending multipart/form-data type req…
Browse files Browse the repository at this point in the history
…uest (#14925)
  • Loading branch information
ShivangiReja authored Sep 4, 2020
1 parent 7e1eb9b commit cb4f62a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sdk/core/Azure.Core/src/Shared/Multipart/MultipartContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ private static string GetDefaultBoundary()
/// <param name="request">The request.</param>
public void ApplyToRequest(Request request)
{
request.Headers.Add(HttpHeader.Names.ContentType, $"multipart/{_subtype}; boundary={_boundary}");
request.Headers.SetValue(HttpHeader.Names.ContentType, $"multipart/{_subtype}; boundary={_boundary}");
request.Content = this;
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions sdk/core/Azure.Core/tests/HttpPipelineFunctionalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ public async Task SendMultipartformData()
request.Uri.Reset(testServer.Address);

var content = new MultipartFormDataContent("test_boundary");
content.ApplyToRequest(request);
content.Add(RequestContent.Create(Encoding.UTF8.GetBytes("John")), "FirstName", "file_name.txt", new Dictionary<string, string>
{
{ "Content-Type", "text/plain; charset=utf-8" }
Expand All @@ -414,7 +413,7 @@ public async Task SendMultipartformData()
{ "Content-Type", "text/plain; charset=utf-8" }
});

request.Content = content;
content.ApplyToRequest(request);

using Response response = await ExecuteRequest(request, httpPipeline);
Assert.AreEqual(response.Status, 200);
Expand Down
3 changes: 1 addition & 2 deletions sdk/core/Azure.Core/tests/MultipartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public async Task SendMultipartData()

Guid batchGuid = Guid.NewGuid();
var content = new MultipartContent(Mixed, $"batch_{batchGuid}");
content.ApplyToRequest(request);

Guid changesetGuid = Guid.NewGuid();
var changeset = new MultipartContent(Mixed, $"changeset_{changesetGuid}");
Expand Down Expand Up @@ -228,7 +227,7 @@ public async Task SendMultipartData()
patchReq.Content = RequestContent.Create(Encoding.UTF8.GetBytes(patchBody));
changeset.Add(new RequestRequestContent(patchReq), new Dictionary<string, string> { { HttpHeader.Names.ContentType, "application/http" }, { cteHeaderName, Binary } });

request.Content = content;
content.ApplyToRequest(request);
var memStream = new MemoryStream();
await content.WriteToAsync(memStream, default);
memStream.Position = 0;
Expand Down

0 comments on commit cb4f62a

Please sign in to comment.