diff --git a/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs b/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs index ca5412816..62171a318 100644 --- a/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs +++ b/src/System.Web.Http/Batch/DefaultHttpBatchHandler.cs @@ -187,7 +187,7 @@ public virtual async Task> 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); } diff --git a/test/System.Web.Http.Test/Batch/DefaultHttpBatchHandlerTest.cs b/test/System.Web.Http.Test/Batch/DefaultHttpBatchHandlerTest.cs index 5b3033684..d6283e1e9 100644 --- a/test/System.Web.Http.Test/Batch/DefaultHttpBatchHandlerTest.cs +++ b/test/System.Web.Http.Test/Batch/DefaultHttpBatchHandlerTest.cs @@ -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")) + }, + RequestUri = new Uri("https://example.com/") + }; + + IList 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() {