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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170222-09" />
<!-- <PackageReference Include="Microsoft.NETCore.App" Version="1.0.2" /> -->
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<!-- This is needed for discovering tests in test explorer -->
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<RestorePackagesPath>$(LibraryNugetPackageFolder)</RestorePackagesPath>
<NugetCommonProfileTags/>
<NugetCommonProfileTags />
<PackageOutputPath>$(BuiltPackageOutputDir)</PackageOutputPath>
<AddProjectReferenceForDebuggingPurpose>false</AddProjectReferenceForDebuggingPurpose>
<AddNugetReferenceForCIandCmdlineBuild>true</AddNugetReferenceForCIandCmdlineBuild>
Expand All @@ -25,7 +25,12 @@
<OutputPath>bin\$(Configuration)\</OutputPath>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.WebListener" Version="1.0.2" />
<PackageReference Include="xunit" Version="2.3.0-beta1-build3642" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170222-09" />
Expand All @@ -43,7 +48,7 @@
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
<TargetFrameworks>netcoreapp1.1;net452</TargetFrameworks>
</PropertyGroup>

<!--Do not remove until VS Test Tools fixes #472-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Azure.Batch.Unit.Tests
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Batch.Protocol;
using Microsoft.Net.Http.Server;
using Xunit;

public class HttpClientBehaviorTests
{
private const string url = "http://localhost:2055";

[Theory]
[MemberData(nameof(HttpMethods))]
public async Task HttpClient_IncludesContentLengthHeaderOnExpectedHttpVerbs(HttpMethod httpMethod)
{
BatchSharedKeyCredential creds = new BatchSharedKeyCredential(ClientUnitTestCommon.DummyAccountName, ClientUnitTestCommon.DummyAccountKey);

HttpRequestMessage message = new HttpRequestMessage(httpMethod, url);
message.Headers.Add("client-request-id", Guid.NewGuid().ToString());

await creds.ProcessHttpRequestAsync(message, CancellationToken.None);
Assert.NotNull(message.Headers.Authorization);

var settings = new WebListenerSettings()
{
Authentication = { Schemes = AuthenticationSchemes.None },
UrlPrefixes = { url }
};
using (WebListener listener = new WebListener(settings))
{
listener.Start();
Task listenTask = AcceptAndAssertAsync(httpMethod, listener, AssertRequestHasExpectedContentLength);

HttpClient client = new HttpClient();
await client.SendAsync(message);

await listenTask;
}
}

private static IEnumerable<object[]> HttpMethods()
{
yield return new[] { HttpMethod.Delete };
yield return new[] { HttpMethod.Post };
yield return new[] { HttpMethod.Get };
yield return new[] { HttpMethod.Head };
yield return new[] { new HttpMethod("PATCH") };
yield return new[] { HttpMethod.Put };
yield return new[] { HttpMethod.Options };
}

private static async Task AcceptAndAssertAsync(HttpMethod httpMethod, WebListener listener, Action<HttpMethod, RequestContext> assertLambda)
{
using (RequestContext ctx = await listener.AcceptAsync())
{
assertLambda(httpMethod, ctx);
ctx.Response.StatusCode = 200;
}
}

private static void AssertRequestHasExpectedContentLength(HttpMethod httpMethod, RequestContext ctx)
{
if (httpMethod == HttpMethod.Head || httpMethod == HttpMethod.Get)
{
Assert.DoesNotContain(ctx.Request.Headers.Keys, str => str == "Content-Length");
}
else if (httpMethod == HttpMethod.Delete || httpMethod == new HttpMethod("PATCH") || httpMethod == HttpMethod.Options)
{
#if !FullNetFx
Assert.DoesNotContain(ctx.Request.Headers.Keys, str => str == "Content-Length");
#else
Assert.Contains(ctx.Request.Headers.Keys, str => str == "Content-Length");
Assert.Equal("0", ctx.Request.Headers["Content-Length"].Single());
#endif
}
else if (httpMethod == HttpMethod.Post || httpMethod == HttpMethod.Put)
{
Assert.Contains(ctx.Request.Headers.Keys, str => str == "Content-Length");
Assert.Equal("0", ctx.Request.Headers["Content-Length"].Single());
}
else
{
throw new ArgumentException($"Unexpected HTTP request type: {httpMethod}");
}
}
}
}
4 changes: 2 additions & 2 deletions src/SDKs/Batch/DataPlane/Azure.Batch/AssemblyAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
[assembly: AssemblyTitle("Microsoft.Azure.Batch")]
[assembly: AssemblyDescription("Client library for interacting with the Azure Batch service.")]

[assembly: AssemblyVersion("7.0.0.0")]
[assembly: AssemblyFileVersion("7.0.0.0")]
[assembly: AssemblyVersion("7.0.1.0")]
[assembly: AssemblyFileVersion("7.0.1.0")]
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft Azure")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation. All rights reserved.")]
Expand Down
2 changes: 1 addition & 1 deletion src/SDKs/Batch/DataPlane/Azure.Batch/Azure.Batch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<PackageId>Azure.Batch</PackageId>
<Description>This client library provides access to the Microsoft Azure Batch service.</Description>
<VersionPrefix>7.0.0</VersionPrefix>
<VersionPrefix>7.0.1</VersionPrefix>
<DefineConstants>$(DefineConstants);CODESIGN</DefineConstants>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Microsoft.Azure.Batch</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,27 @@ public override Task ProcessHttpRequestAsync(HttpRequestMessage httpRequest, Can
signature.Append(httpRequest.Content != null && httpRequest.Content.Headers.Contains("Content-Language") ? httpRequest.Content.Headers.GetValues("Content-Language").FirstOrDefault() : string.Empty).Append('\n');

// Handle content length
if (httpRequest.Content != null)
{
signature.Append(httpRequest.Content.Headers.ContentLength.HasValue ? httpRequest.Content.Headers.ContentLength.ToString() : string.Empty).Append('\n');
}
else
long? contentLength = httpRequest.Content?.Headers?.ContentLength;

if (contentLength == null)
{
// Because C# httpRequest adds a content-length = 0 header for POST and DELETE even if there is no body, we have to
// sign the request knowing that there will be content-length set. For all other methods that have no body, there will be
// no content length set and thus we append \n with no 0.
if ((httpRequest.Method == HttpMethod.Delete) || (httpRequest.Method == HttpMethod.Post))
// Because C# httpRequest adds a content-length = 0 header for DELETE, PATCH, and OPTIONS even if there is no body (but only in netframework), we have to
// sign the request knowing that there will be content-length set.
#if FullNetFx
if (httpRequest.Method == HttpMethod.Delete || httpRequest.Method == new HttpMethod("PATCH") || httpRequest.Method == HttpMethod.Options)
{
signature.Append("0\n");
contentLength = 0;
}
else
#endif

// Because C# httpRequest adds a content-length = 0 header for POST even if there is no body, we have to
// sign the request knowing that there will be content-length set.
if (httpRequest.Method == HttpMethod.Post)
{
signature.Append('\n');
contentLength = 0;
}
}
signature.Append(contentLength).Append('\n');

signature.Append(httpRequest.Content != null && httpRequest.Content.Headers.Contains("Content-MD5") ? httpRequest.Content.Headers.GetValues("Content-MD5").FirstOrDefault() : string.Empty).Append('\n');
signature.Append(httpRequest.Content != null && httpRequest.Content.Headers.Contains("Content-Type") ? httpRequest.Content.Headers.GetValues("Content-Type").FirstOrDefault() : string.Empty).Append('\n');
Expand Down
8 changes: 8 additions & 0 deletions src/SDKs/Batch/DataPlane/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
### Upcoming changes
These changes are planned but haven't been published yet.

### Changes in 7.0.1
#### Bug fixes
- Fixed a bug where requests using HTTP DELETE (for example, `DeletePool` and `DeleteJob`) failed with an authentication error in the netstandard package. This was due to a change made to `HttpClient` in netcore.
- This bug impacted the 6.1.0 release as well.

#### REST API version
This version of the Batch .NET client library targets version 2017-05-01.5.0 of the Azure Batch REST API.

### Changes in 7.0.0
#### License
Moved source code and NuGet package from Apache 2.0 license to MIT license. This is more consistent with the other Azure SDKs as well as other open source projects from Microsoft such as .NET.
Expand Down