-
Notifications
You must be signed in to change notification settings - Fork 4.9k
skip content-length on DELETE and OPTIONS methods with no body #32259
Changes from 8 commits
ce78ff6
1c92ea0
0da5a36
92efea2
15288d6
aea40a3
ed7c41b
dc8f2ae
6c52cfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,16 +3,18 @@ | |||
// See the LICENSE file in the project root for more information. | ||||
|
||||
using System; | ||||
using System.Collections.Generic; | ||||
using System.IO; | ||||
using System.Net.Http.Headers; | ||||
using System.Net.Test.Common; | ||||
using System.Threading; | ||||
using System.Threading.Tasks; | ||||
|
||||
using Xunit; | ||||
|
||||
namespace System.Net.Http.Functional.Tests | ||||
{ | ||||
public class HttpRequestMessageTest | ||||
public class HttpRequestMessageTest : HttpClientTestBase | ||||
{ | ||||
Version _expectedRequestMessageVersion = !PlatformDetection.IsFullFramework ? new Version(2,0) : new Version(1, 1); | ||||
|
||||
|
@@ -215,6 +217,43 @@ public void ToString_DefaultAndNonDefaultInstance_DumpAllFields() | |||
"}", rm.ToString()); | ||||
} | ||||
|
||||
[Theory] | ||||
[InlineData("DELETE")] | ||||
[InlineData("OPTIONS")] | ||||
[InlineData("HEAD")] | ||||
public async Task HttpRequest_BodylessMethod_NoContentLength(string method) | ||||
{ | ||||
if (IsWinHttpHandler || IsNetfxHandler || IsUapHandler) | ||||
{ | ||||
// Some platform handlers differ but we don't take it as failure. | ||||
return; | ||||
} | ||||
|
||||
using (HttpClient client = new HttpClient()) | ||||
{ | ||||
await LoopbackServer.CreateServerAsync(async (server, uri) => | ||||
{ | ||||
var request = new HttpRequestMessage(); | ||||
request.RequestUri = uri; | ||||
request.Method = new HttpMethod(method); | ||||
|
||||
Task<HttpResponseMessage> requestTask = client.SendAsync(request); | ||||
await server.AcceptConnectionAsync(async connection => | ||||
{ | ||||
List<string> headers = await connection.ReadRequestHeaderAsync(); | ||||
foreach (string line in headers) | ||||
{ | ||||
// There should be no Content-Length header. | ||||
Assert.False(line.StartsWith("Content-length:", StringComparison.InvariantCultureIgnoreCase)); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should use See example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is that better? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It produces better output when things fail. And it is pattern we already use elsewhere in the tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. Existing pattern also exit but I can change it as you suggested. |
||||
} | ||||
|
||||
await connection.SendResponseAsync(); | ||||
await requestTask; | ||||
}); | ||||
}); | ||||
} | ||||
} | ||||
|
||||
#region Helper methods | ||||
|
||||
private class MockContent : HttpContent | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a change request just an observation, you could use
is
here to make this cleaner.return !(this is HttpMethod.Get || this is HttpMethod.Head || this is HttpMethod.Connect || this is HttpMethod.Options || this is HttpMethod.Delete);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ReferenceEquals? Why not String.Equals()? Does this work with
var method = new System.Net.Http.HttpMethod("GET");
?... I see, .Normalize() does the magic!