-
Notifications
You must be signed in to change notification settings - Fork 191
Adding HTTP method constants #712
Changes from 7 commits
f9a9bde
b79adf1
3426646
8a3a4e0
0262337
8346fa0
4e93c97
3759ad7
d5edcab
80f0f21
c443c51
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.AspNetCore.Http | ||
{ | ||
public static class HttpMethods | ||
{ | ||
public const string Connect = "CONNECT"; | ||
public const string Delete = "DELETE"; | ||
public const string Get = "GET"; | ||
public const string Head = "HEAD"; | ||
public const string Options = "OPTIONS"; | ||
public const string Patch = "PATCH"; | ||
public const string Post = "POST"; | ||
public const string Put = "PUT"; | ||
public const string Trace = "TRACE"; | ||
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. I'm for keeping these const. ReferenceEquals still works across assembly boundaries. Just don't mess up 😛 . 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. static readonly 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. Yeah, constants would be nicer (e.g they could be used for attribute values) 👍 |
||
|
||
public static bool IsConnectMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Connect, method) || StringComparer.OrdinalIgnoreCase.Equals(Connect, method); | ||
} | ||
|
||
public static bool IsDeleteMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Delete, method) || StringComparer.OrdinalIgnoreCase.Equals(Delete, method); | ||
} | ||
|
||
public static bool IsGetMethod(string method) | ||
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. HttpMethod.IsGetMethod(string) seems redundant. What about just HttpMethod.IsGet(string)? |
||
{ | ||
return object.ReferenceEquals(Get, method) || StringComparer.OrdinalIgnoreCase.Equals(Get, method); | ||
} | ||
|
||
public static bool IsHeadMethod(string method){ | ||
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. formatting? |
||
return object.ReferenceEquals(Head, method) || StringComparer.OrdinalIgnoreCase.Equals(Head, method); | ||
} | ||
|
||
public static bool IsOptionsMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Options, method) || StringComparer.OrdinalIgnoreCase.Equals(Options, method); | ||
} | ||
|
||
public static bool IsPatchMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Patch, method) || StringComparer.OrdinalIgnoreCase.Equals(Patch, method); | ||
} | ||
|
||
public static bool IsPostMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Post, method) || StringComparer.OrdinalIgnoreCase.Equals(Post, method); | ||
} | ||
|
||
public static bool IsPutMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Put, method) || StringComparer.OrdinalIgnoreCase.Equals(Put, method); | ||
} | ||
|
||
public static bool IsTraceMethod(string method) | ||
{ | ||
return object.ReferenceEquals(Trace, method) || StringComparer.OrdinalIgnoreCase.Equals(Trace, method); | ||
} | ||
|
||
public static bool Equals(string left, string right) | ||
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. This method is pointless... We hard code a few methods there's no point having a case insensitive overload here. It adds nothing.. 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. I'm gonna let you and @Tratcher settle this... 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. @Tratcher lets decide on this offline. 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. Is this really necessary? If anything this could be private and called by the Is* methods. 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. There was a big discussion on this. We're taking it out 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. its decided, nuke it. |
||
{ | ||
return StringComparer.OrdinalIgnoreCase.Equals(left, right); | ||
} | ||
} | ||
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. we should still have the Equals(string, string) method |
||
} |
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.
Should this be singular?
HttpMethod.Get
HttpMethod.IsGet(string)
HttpMethod.Equals(string, string)
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.
Agreed. This is similar to a non-flag enum.