Skip to content

Commit ea006ef

Browse files
committed
Merge branch 'user/carl-aggregate-methods' into develop
Cherry picked from ThreeMammals#1389
2 parents cfbdb35 + d56ceec commit ea006ef

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

docs/features/requestaggregation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,6 @@ Gotcha's / Further info
206206

207207
You cannot use Routes with specific RequestIdKeys as this would be crazy complicated to track.
208208

209-
Aggregation only supports the GET HTTP Verb.
209+
Aggregation supports the GET HTTP Verb for pure REST, it supports other verbs for apis which do not fully follow REST.
210+
210211

src/Ocelot/Configuration/Creator/AggregatesCreator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ public List<Route> Create(FileConfiguration fileConfiguration, List<Route> route
2323
}
2424

2525
private Route SetUpAggregateRoute(IEnumerable<Route> routes, FileAggregateRoute aggregateRoute, FileGlobalConfiguration globalConfiguration)
26-
{
26+
{
27+
if (!aggregateRoute.UpstreamHttpMethod.Any())
28+
{
29+
// Default Method to Get for standard use case
30+
aggregateRoute.UpstreamHttpMethod.Add("Get");
31+
}
32+
2733
var applicableRoutes = new List<DownstreamRoute>();
2834
var allRoutes = routes.SelectMany(x => x.DownstreamRoute);
2935

src/Ocelot/Configuration/File/FileAggregateRoute.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ namespace Ocelot.Configuration.File
33
using System.Collections.Generic;
44

55
public class FileAggregateRoute : IRoute
6-
{
6+
{
77
public List<string> RouteKeys { get; set; }
88
public List<AggregateRouteConfig> RouteKeysConfig { get; set; }
99
public string UpstreamPathTemplate { get; set; }
1010
public string UpstreamHost { get; set; }
1111
public bool RouteIsCaseSensitive { get; set; }
1212
public string Aggregator { get; set; }
13-
14-
// Only supports GET..are you crazy!! POST, PUT WOULD BE CRAZY!! :)
1513
public List<string> UpstreamHttpMethod
16-
{
17-
get { return new List<string> { "Get" }; }
18-
}
14+
{ get; private set; } = new List<string>();
1915

2016
public int Priority { get; set; } = 1;
2117
}

test/Ocelot.AcceptanceTests/AggregateTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Ocelot.AcceptanceTests
22
{
33
using Microsoft.AspNetCore.Http;
4+
using Newtonsoft.Json;
45
using Ocelot.Configuration.File;
56
using Ocelot.Middleware;
67
using Ocelot.Multiplexer;
@@ -138,6 +139,20 @@ public void should_fix_issue_597()
138139
.BDDfy();
139140
}
140141

142+
[Fact]
143+
public void should_allow_get_method()
144+
{
145+
FileAggregateRoute route = JsonConvert.DeserializeObject<FileAggregateRoute>("{\"UpstreamHttpMethod\":[\"Get\"]}");
146+
Assert.Contains("Get", route.UpstreamHttpMethod);
147+
}
148+
149+
[Fact]
150+
public void should_allow_post_method()
151+
{
152+
FileAggregateRoute route = JsonConvert.DeserializeObject<FileAggregateRoute>("{\"UpstreamHttpMethod\":[\"Post\"]}");
153+
Assert.Contains("Post", route.UpstreamHttpMethod);
154+
}
155+
141156
[Fact]
142157
public void should_return_response_200_with_advanced_aggregate_configs()
143158
{

0 commit comments

Comments
 (0)