Skip to content

Commit 2650192

Browse files
committed
[add] add HTTP QUERY method support with QueryAttribute and HttpMethod.Query
1 parent 35ee24f commit 2650192

10 files changed

Lines changed: 37 additions & 5 deletions

File tree

src/Simplify.Web.Tests/Controllers/Resolution/Stages/RouteMatchingStageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void Execute_NoRespectiveMethod_ExecutionStoppedAndNoParametersSet()
5151
[TestCase(HttpMethod.Patch)]
5252
[TestCase(HttpMethod.Delete)]
5353
[TestCase(HttpMethod.Options)]
54+
[TestCase(HttpMethod.Query)]
5455
public void Execute_MatchedMethodButNotMatchedRoute_ExecutionStoppedAndIsMatchedSetAndNoRouteParametersSet(HttpMethod httpMethod)
5556
{
5657
// Arrange
@@ -96,6 +97,7 @@ public void Execute_MatchedMethodButNotMatchedRoute_ExecutionStoppedAndIsMatched
9697
[TestCase(HttpMethod.Patch)]
9798
[TestCase(HttpMethod.Delete)]
9899
[TestCase(HttpMethod.Options)]
100+
[TestCase(HttpMethod.Query)]
99101
public void Execute_MatchedMethodAndMatchedRoute_IsMatchedAndRouteParametersAreSet(HttpMethod httpMethod)
100102
{
101103
// Arrange

src/Simplify.Web.Tests/Controllers/V1/Metadata/MetadataFactoryTests/Controller1MetadataFactoryTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private static void AssertExecParameters(IControllerMetadata metaData)
4242
Assert.That(metaData.ExecParameters, Is.Not.Null);
4343
Assert.That(metaData.ExecParameters!.RunPriority, Is.EqualTo(1));
4444

45-
Assert.That(metaData.ExecParameters.Routes.Count, Is.EqualTo(6));
45+
Assert.That(metaData.ExecParameters.Routes.Count, Is.EqualTo(7));
4646

4747
var firstControllerRoute = metaData.ExecParameters.Routes.First(x => x.Key == HttpMethod.Get);
4848

@@ -60,5 +60,6 @@ private static void AssertExecParametersRoutes(ControllerExecParameters execPara
6060
Assert.That(execParameters.Routes[HttpMethod.Patch].Path, Is.EqualTo("/test-action3"));
6161
Assert.That(execParameters.Routes[HttpMethod.Delete].Path, Is.EqualTo("/test-action4"));
6262
Assert.That(execParameters.Routes[HttpMethod.Options].Path, Is.EqualTo("/test-action5"));
63+
Assert.That(execParameters.Routes[HttpMethod.Query].Path, Is.EqualTo("/test-action6"));
6364
}
6465
}

src/Simplify.Web.Tests/Controllers/V1/Metadata/MetadataFactoryTests/TestTypes/AllAttributesController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Simplify.Web.Tests.Controllers.V1.Metadata.MetadataFactoryTests.TestTy
99
[Patch("/test-action3")]
1010
[Delete("/test-action4")]
1111
[Options("/test-action5")]
12+
[Query("/test-action6")]
1213
[Http403]
1314
[Http404]
1415
[Priority(1)]

src/Simplify.Web.Tests/Controllers/V2/Metadata/MetadataFactoryTests/Controller2MetadataFactoryTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static void AssertExecParameters(IControllerMetadata metaData)
6565
Assert.That(metaData.ExecParameters, Is.Not.Null);
6666
Assert.That(metaData.ExecParameters!.RunPriority, Is.EqualTo(1));
6767

68-
Assert.That(metaData.ExecParameters.Routes.Count, Is.EqualTo(6));
68+
Assert.That(metaData.ExecParameters.Routes.Count, Is.EqualTo(7));
6969

7070
var firstControllerRoute = metaData.ExecParameters.Routes.First(x => x.Key == HttpMethod.Get);
7171

@@ -83,5 +83,6 @@ private static void AssertExecParametersRoutes(ControllerExecParameters execPara
8383
Assert.That(execParameters.Routes[HttpMethod.Patch].Path, Is.EqualTo("/test-action3"));
8484
Assert.That(execParameters.Routes[HttpMethod.Delete].Path, Is.EqualTo("/test-action4"));
8585
Assert.That(execParameters.Routes[HttpMethod.Options].Path, Is.EqualTo("/test-action5"));
86+
Assert.That(execParameters.Routes[HttpMethod.Query].Path, Is.EqualTo("/test-action6"));
8687
}
8788
}

src/Simplify.Web.Tests/Controllers/V2/Metadata/MetadataFactoryTests/TestTypes/AllAttributesControllerV2.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Simplify.Web.Tests.Controllers.V2.Metadata.MetadataFactoryTests.TestTy
99
[Patch("/test-action3")]
1010
[Delete("/test-action4")]
1111
[Options("/test-action5")]
12+
[Query("/test-action6")]
1213
[Http403]
1314
[Http404]
1415
[Priority(1)]

src/Simplify.Web.Tests/Model/Binding/Parsers/TestTypes/TestController1.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Simplify.Web.Tests.Model.Binding.Parsers.TestTypes;
99
[Patch("/testaction3")]
1010
[Delete("/testaction4")]
1111
[Options("/testaction5")]
12+
[Query("/testaction6")]
1213
[Http403]
1314
[Http404]
1415
[Priority(1)]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace Simplify.Web.Attributes;
4+
5+
/// <summary>
6+
/// Sets the controller HTTP QUERY request route path.
7+
/// </summary>
8+
/// <seealso cref="ControllerRouteAttribute" />
9+
/// <remarks>
10+
/// Initializes a new instance of the <see cref="QueryAttribute" /> class.
11+
/// </remarks>
12+
/// <param name="route">The route.</param>
13+
[AttributeUsage(AttributeTargets.Class)]
14+
public class QueryAttribute(string route) : ControllerRouteAttribute(route);

src/Simplify.Web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [5.3.1] - Unreleased
44

5+
### Added
6+
7+
- HTTP QUERY method support via HttpMethod.Query and the [Query] controller route attribute.
8+
59
### Security
610

711
- Redirector: reject relative redirect URLs containing control characters (e.g. tab) in

src/Simplify.Web/Http/HttpMethod.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@ public enum HttpMethod
3838
/// <summary>
3939
/// The OPTIONS HTTP method.
4040
/// </summary>
41-
Options
41+
Options,
42+
43+
/// <summary>
44+
/// The QUERY HTTP method.
45+
/// </summary>
46+
Query
4247
}

src/Simplify.Web/Http/Relations.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public static class Relations
1919
{ HttpMethod.Put, typeof(PutAttribute) },
2020
{ HttpMethod.Patch, typeof(PatchAttribute) },
2121
{ HttpMethod.Delete, typeof(DeleteAttribute) },
22-
{ HttpMethod.Options, typeof(OptionsAttribute) }
22+
{ HttpMethod.Options, typeof(OptionsAttribute) },
23+
{ HttpMethod.Query, typeof(QueryAttribute) }
2324
};
2425

2526
/// <summary>
@@ -32,6 +33,7 @@ public static class Relations
3233
{ HttpMethod.Put, "PUT" },
3334
{ HttpMethod.Patch, "PATCH" },
3435
{ HttpMethod.Delete, "DELETE" },
35-
{ HttpMethod.Options, "OPTIONS" }
36+
{ HttpMethod.Options, "OPTIONS" },
37+
{ HttpMethod.Query, "QUERY" }
3638
};
3739
}

0 commit comments

Comments
 (0)