-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* temp commit * trying to work out how to expose the http handlers in a decent way.. * pissing about at lunch * changed to func so you can instanciate object or new it up each time * docs for dele handlers * upgraded to sdk 2.1.4 * some validation for consul services
- Loading branch information
1 parent
ef3c4f6
commit 98133d9
Showing
48 changed files
with
1,352 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Delegating Handers | ||
================== | ||
|
||
Ocelot allows the user to add delegating handlers to the HttpClient transport. This feature was requested `GitHub #208 <https://github.com/TomPallister/Ocelot/issues/208>`_ and I decided that it was going to be useful in various ways. | ||
|
||
Usage | ||
^^^^^^ | ||
|
||
In order to add delegating handlers to the HttpClient transport you need to do the following. | ||
|
||
.. code-block:: csharp | ||
services.AddOcelot() | ||
.AddDelegatingHandler(() => new FakeHandler()) | ||
.AddDelegatingHandler(() => new FakeHandler()); | ||
Or for singleton like behaviour.. | ||
|
||
.. code-block:: csharp | ||
var handlerOne = new FakeHandler(); | ||
var handlerTwo = new FakeHandler(); | ||
services.AddOcelot() | ||
.AddDelegatingHandler(() => handlerOne) | ||
.AddDelegatingHandler(() => handlerTwo); | ||
You can have as many DelegatingHandlers as you want and they are run in a first in first out order. If you are using Ocelot's QoS functionality then that will always be run after your last delegating handler. | ||
|
||
In order to create a class that can be used a delegating handler it must look as follows | ||
|
||
.. code-block:: csharp | ||
public class FakeHandler : DelegatingHandler | ||
{ | ||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
//do stuff and optionally call the base handler.. | ||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
Hopefully other people will find this feature useful! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"projects": [ "src", "test" ], | ||
"sdk": { | ||
"version": "2.0.2" | ||
"version": "2.1.4" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Ocelot/DependencyInjection/IOcelotAdministrationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Ocelot.DependencyInjection | ||
{ | ||
public interface IOcelotAdministrationBuilder | ||
{ | ||
IOcelotAdministrationBuilder AddRafty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Ocelot.Raft; | ||
using Rafty.Concensus; | ||
using Rafty.FiniteStateMachine; | ||
using Rafty.Infrastructure; | ||
using Rafty.Log; | ||
|
||
namespace Ocelot.DependencyInjection | ||
{ | ||
public class OcelotAdministrationBuilder : IOcelotAdministrationBuilder | ||
{ | ||
private readonly IServiceCollection _services; | ||
private readonly IConfiguration _configurationRoot; | ||
|
||
public OcelotAdministrationBuilder(IServiceCollection services, IConfiguration configurationRoot) | ||
{ | ||
_configurationRoot = configurationRoot; | ||
_services = services; | ||
} | ||
|
||
public IOcelotAdministrationBuilder AddRafty() | ||
{ | ||
var settings = new InMemorySettings(4000, 5000, 100, 5000); | ||
_services.AddSingleton<ILog, SqlLiteLog>(); | ||
_services.AddSingleton<IFiniteStateMachine, OcelotFiniteStateMachine>(); | ||
_services.AddSingleton<ISettings>(settings); | ||
_services.AddSingleton<IPeersProvider, FilePeersProvider>(); | ||
_services.AddSingleton<INode, Node>(); | ||
_services.Configure<FilePeers>(_configurationRoot); | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ public UnableToFindLoadBalancerError(string message) | |
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.