Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

skip content-length on DELETE and OPTIONS methods with no body #32259

Merged
merged 9 commits into from
Sep 17, 2018

Conversation

wfurt
Copy link
Member

@wfurt wfurt commented Sep 12, 2018

fixes #31172

@wfurt
Copy link
Member Author

wfurt commented Sep 12, 2018

@dotnet-bot test Outerloop Windows x64 Debug Build
@dotnet-bot test Outerloop Linux x64 Debug Build
@dotnet-bot test Outerloop NETFX x86 Debug Build
@dotnet-bot test Outerloop UWP CoreCLR x64 Debug Build
@dotnet-bot test Outerloop OSX x64 Debug Build

@davidsh davidsh requested a review from geoffkizer September 12, 2018 17:24
@wfurt
Copy link
Member Author

wfurt commented Sep 12, 2018

@dotnet-bot test Outerloop Windows x64 Debug Build
@dotnet-bot test Outerloop Linux x64 Debug Build
@dotnet-bot test Outerloop NETFX x86 Debug Build
@dotnet-bot test Outerloop UWP CoreCLR x64 Debug Build
@dotnet-bot test Outerloop OSX x64 Debug Build

@wfurt wfurt requested a review from a team September 12, 2018 17:39
[InlineData("DELETE")]
[InlineData("OPTIONS")]
[InlineData("HEAD")]
public async Task HttpRequest_BodylessMethod_NoContentLenght(string method)

Choose a reason for hiding this comment

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

Typo: "Lenght"

@geoffkizer
Copy link

Minor issue above, otherwise LGTM.

@wfurt
Copy link
Member Author

wfurt commented Sep 13, 2018

@dotnet-bot test Outerloop Windows x64 Debug Build
@dotnet-bot test Outerloop Linux x64 Debug Build
@dotnet-bot test Outerloop NETFX x86 Debug Build
@dotnet-bot test Outerloop UWP CoreCLR x64 Debug Build
@dotnet-bot test Outerloop OSX x64 Debug Build

{
if (IsWinHttpHandler || IsNetfxHandler || IsUapHandler)
{
// WinHttp differ on some versions.
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment needs to be updated for other handlers as well.

Task<HttpResponseMessage> requestTask = client.SendAsync(request);
await server.AcceptConnectionAsync(async connection =>
{
var headers = await connection.ReadRequestHeaderAsync();
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use 'var' since the type is not obvious.

foreach (string line in headers)
{
// There should be no Content-Length header.
Assert.False(line.StartsWith("Content-length:", StringComparison.InvariantCultureIgnoreCase));
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use Assert.DoesNotContain pattern instead of Assert.False.

See example:

Assert.DoesNotContain(receivedRequest, line => line.StartsWith("Transfer-Encoding"));

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is that better?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@davidsh davidsh left a comment

Choose a reason for hiding this comment

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

Added comments.

Copy link
Contributor

@rmkerr rmkerr left a comment

Choose a reason for hiding this comment

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

LGTM once all of the tests pass.

@davidsh
Copy link
Contributor

davidsh commented Sep 15, 2018

@dotnet-bot test Outerloop Windows x64 Debug Build
@dotnet-bot test Outerloop Linux x64 Debug Build
@dotnet-bot test Outerloop NETFX x86 Debug Build
@dotnet-bot test Outerloop UWP CoreCLR x64 Debug Build
@dotnet-bot test Outerloop OSX x64 Debug Build

@@ -174,7 +174,8 @@ internal bool MustHaveRequestBody
// Normalize before calling this
Debug.Assert(ReferenceEquals(this, Normalize(this)));

return !ReferenceEquals(this, HttpMethod.Get) && !ReferenceEquals(this, HttpMethod.Head) && !ReferenceEquals(this, HttpMethod.Connect);
return !ReferenceEquals(this, HttpMethod.Get) && !ReferenceEquals(this, HttpMethod.Head) && !ReferenceEquals(this, HttpMethod.Connect) &&
Copy link
Contributor

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);

Copy link

@samsosa samsosa Sep 17, 2018

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!

@wfurt wfurt merged commit 9921193 into dotnet:master Sep 17, 2018
@karelz karelz added this to the 3.0 milestone Oct 8, 2018
@wfurt wfurt deleted the fix_31172 branch June 15, 2020 18:21
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…t/corefx#32259)

* skip content-length on DELETE and OPTIONS methods

* breakup long line

* update after sync up

* fix spelling

* skip new test on winhttp

* disable test also on netfx and uap

* feedback from reviews

* use Assert.DoesNotContain for assert


Commit migrated from dotnet/corefx@9921193
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
8 participants