Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Refactored to use the fields from the HttpMethods class#1128

Merged
mikaelm12 merged 2 commits into
devfrom
mikaelm12/UseHttpMethodsConstants
Sep 29, 2016
Merged

Refactored to use the fields from the HttpMethods class#1128
mikaelm12 merged 2 commits into
devfrom
mikaelm12/UseHttpMethodsConstants

Conversation

@mikaelm12

Copy link
Copy Markdown
Contributor

@dnfclas

dnfclas commented Sep 28, 2016

Copy link
Copy Markdown

Hi @mikaelm12, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

[InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)]
[InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)]
[InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)]
[InlineData("CONNECT / HTTP/1.1", ' ', true,"CONNECT")]

@mikeharder mikeharder Sep 28, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason to hardcode "CONNECT" rather than using HttpMethods.Connect, as is done in the product code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can't use HttpMethods.Connect here because its not a const.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fix the missing space though.

if ((value & _mask4Chars) == _httpGetMethodLong)
{
knownMethod = HttpGetMethod;
knownMethod = HttpMethods.Get;

@mikeharder mikeharder Sep 28, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be a tiny performance degradation since the value is changing from const to static readonly. Is there a reason the properties on HttpMethods are static readonly rather than const? I see the HttpMethods type is new for 1.1, so we should be able to change the properties to const now. After 1.1 ships it would be a breaking change.

I don't see any possible way the value of these properties would change in the future, so const should be safe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I doubt the performance will degrade

{
private static readonly Encoding _utf8 = Encoding.UTF8;

public const string HttpConnectMethod = "CONNECT";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are breaking changes to public APIs on internal types allowed in 1.1?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's in an "Internal" namespace.

{
private static readonly Encoding _utf8 = Encoding.UTF8;

public const string HttpConnectMethod = "CONNECT";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's in an "Internal" namespace.

if ((value & _mask4Chars) == _httpGetMethodLong)
{
knownMethod = HttpGetMethod;
knownMethod = HttpMethods.Get;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@halter73

Copy link
Copy Markdown
Member

@mikaelm12 You know how to run the plaintext benchmarks, right? I really don't expect this change will make any difference, but it's easy enough to test using @mikeharder's BenchmarksDriver.

[InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)]
[InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)]
[InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)]
[InlineData("CONNECT / HTTP/1.1", ' ', true,"CONNECT")]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could use MemberData but meh. We could have a second set of tests that verify reference equality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"type": "build"
}
},
"Microsoft.AspNetCore.Http.Abstractions": "1.1.0-*"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sort

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmmmm, this is a new dependency? Doesn't this come in transitively already?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, it should be coming from Microsoft.AspNetCore.Hosting transitively.

@muratg muratg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@mikaelm12 mikaelm12 merged commit 12adc7d into dev Sep 29, 2016
@mikaelm12 mikaelm12 deleted the mikaelm12/UseHttpMethodsConstants branch September 29, 2016 19:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants