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
2 changes: 1 addition & 1 deletion src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public virtual async Task<IList<HttpRequestMessage>> ParseBatchRequestsAsync(Htt
foreach (HttpContent httpContent in streamProvider.Contents)
{
cancellationToken.ThrowIfCancellationRequested();
HttpRequestMessage innerRequest = await httpContent.ReadAsHttpRequestMessageAsync();
HttpRequestMessage innerRequest = request.RequestUri == null ? await httpContent.ReadAsHttpRequestMessageAsync() : await httpContent.ReadAsHttpRequestMessageAsync(request.RequestUri.Scheme);
innerRequest.CopyBatchRequestProperties(request);
requests.Add(innerRequest);
}
Expand Down
23 changes: 23 additions & 0 deletions test/System.Web.Http.Test/Batch/DefaultHttpBatchHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,29 @@ public async Task ParseBatchRequestsAsync_Returns_RequestsFromMultipartContent()
Assert.Equal("http://example.com/values", requests[1].RequestUri.AbsoluteUri);
}

[Fact]
public async Task ParseBatchRequestsAsync_Returns_RequestsFromMultipartContent_WithUriSchemeSet_FromRequest()
{
DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(new HttpServer());
HttpRequestMessage request = new HttpRequestMessage
{
Content = new MultipartContent("mixed")
{
new HttpMessageContent(new HttpRequestMessage(HttpMethod.Get, "http://example.com/")),
new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, "https://example.com/values"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a part using a path-only relative URI e.g. /api/values since those are recommended and seem to be more common.

Copy link
Contributor Author

@JamesSinclairBiomni JamesSinclairBiomni Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't supply a relative Uri within a batch request. If I do so then ParseBatchRequestsAsync calls ReadAsMultipartAsync (an extension on HttpContent) and that will throw the following error.

Message: System.IO.IOException : Error reading MIME multipart body part.
---- System.InvalidOperationException : This operation is not supported for a relative URI.

Does this suggest that its absolute uri's by design or is this a different issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd. But, if that's what enforced, so be it. On the off chance this is a bug I should open separately, please paste the full stack trace into this PR.

},
RequestUri = new Uri("https://example.com/")
};

IList<HttpRequestMessage> requests = await batchHandler.ParseBatchRequestsAsync(request, CancellationToken.None);

Assert.Equal(2, requests.Count);
Assert.Equal(HttpMethod.Get, requests[0].Method);
Assert.Equal("https://example.com/", requests[0].RequestUri.AbsoluteUri);
Assert.Equal(HttpMethod.Post, requests[1].Method);
Assert.Equal("https://example.com/values", requests[1].RequestUri.AbsoluteUri);
}

[Fact]
public async Task ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties()
{
Expand Down