Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for other HTTP verbs for aggregation aka UpstreamHttpMethod enhancements #1389

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/features/requestaggregation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Gotchas
-------

* You cannot use Routes with specific **RequestIdKeys** as this would be crazy complicated to track.
* Aggregation only supports the ``GET`` HTTP verb.
* Aggregation supports the ``GET`` HTTP verb for pure REST, it supports other verbs for APIs which do not fully follow REST.
Copy link
Member

Choose a reason for hiding this comment

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

Update docs with info about global static DefaultHttpMethod

* Aggregation allows for the forwarding of ``HttpRequest.Body`` to downstream services by duplicating the body data.
Form data and attached files should also be forwarded.
It is essential to always specify the ``Content-Length`` header in requests to upstream; otherwise, Ocelot will log warnings like *"Aggregation does not support body copy without Content-Length header!"*.
Expand Down
5 changes: 5 additions & 0 deletions src/Ocelot/Configuration/Creator/AggregatesCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public List<Route> Create(FileConfiguration fileConfiguration, List<Route> route

private Route SetUpAggregateRoute(IEnumerable<Route> routes, FileAggregateRoute aggregateRoute, FileGlobalConfiguration globalConfiguration)
{
if (aggregateRoute.UpstreamHttpMethod.Count == 0)
{
aggregateRoute.UpstreamHttpMethod.Add(FileAggregateRoute.DefaultHttpMethod.ToString());
}

var applicableRoutes = new List<DownstreamRoute>();
var allRoutes = routes.SelectMany(x => x.DownstreamRoute);
var downstreamRoutes = aggregateRoute.RouteKeys.Select(routeKey => allRoutes.FirstOrDefault(q => q.Key == routeKey));
Expand Down
46 changes: 24 additions & 22 deletions src/Ocelot/Configuration/File/FileAggregateRoute.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using Microsoft.AspNetCore.Http;
namespace Ocelot.Configuration.File;

public class FileAggregateRoute : IRoute
{
public string Aggregator { get; set; }
public int Priority { get; set; }
public bool RouteIsCaseSensitive { get; set; }
public List<string> RouteKeys { get; set; }
public List<AggregateRouteConfig> RouteKeysConfig { get; set; }
public IDictionary<string, string> UpstreamHeaderTemplates { get; set; }
public string UpstreamHost { get; set; }
public List<string> UpstreamHttpMethod { get; set; }
public string UpstreamPathTemplate { get; set; }

namespace Ocelot.Configuration.File
{
public class FileAggregateRoute : IRoute
public FileAggregateRoute()
{
public List<string> RouteKeys { get; set; }
public List<AggregateRouteConfig> RouteKeysConfig { get; set; }
public string UpstreamPathTemplate { get; set; }
public string UpstreamHost { get; set; }
public bool RouteIsCaseSensitive { get; set; }
public string Aggregator { get; set; }

// Only supports GET..are you crazy!! POST, PUT WOULD BE CRAZY!! :)
public List<string> UpstreamHttpMethod => new() { HttpMethods.Get };
public IDictionary<string, string> UpstreamHeaderTemplates { get; set; }
public int Priority { get; set; } = 1;

public FileAggregateRoute()
{
RouteKeys = new();
RouteKeysConfig = new();
UpstreamHeaderTemplates = new Dictionary<string, string>();
}
Priority = 1;
RouteKeys = new();
RouteKeysConfig = new();
UpstreamHeaderTemplates = new Dictionary<string, string>();
UpstreamHttpMethod = new();
}

/// <summary>This allows to override global default HTTP verb value.</summary>
/// <remarks>Defaults: The <see cref="HttpMethod.Get"/> value.</remarks>
/// <value>A <see cref="HttpMethod"/> value.</value>
public static HttpMethod DefaultHttpMethod { get; set; } = HttpMethod.Get;
}
6 changes: 6 additions & 0 deletions test/Ocelot.AcceptanceTests/AggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,12 @@ public void Should_return_response_200_with_copied_form_sent_on_multiple_service
.BDDfy();
}

[Fact]
[Trait("Feat", "1389")]
public void TODO()
{
}
Comment on lines +656 to +660
Copy link
Member

Choose a reason for hiding this comment

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

Write acceptance tests


private static string FormatFormCollection(IFormCollection reqForm)
{
var sb = new StringBuilder()
Expand Down
Loading