Skip to content

Commit

Permalink
#296 merged develop into this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gardham-Pallister committed Apr 17, 2018
2 parents 2ed37cb + fa09e4c commit b7ff737
Show file tree
Hide file tree
Showing 16 changed files with 624 additions and 428 deletions.
24 changes: 20 additions & 4 deletions docs/features/headerstransformation.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
Headers Transformation
=====================
======================

Ocelot allows the user to transform headers pre and post downstream request. At the moment Ocelot only supports find and replace. This feature was requested `GitHub #190 <https://github.com/TomPallister/Ocelot/issues/190>`_ and I decided that it was going to be useful in various ways.

Add to Request
^^^^^^^^^^^^^^

This feature was requestes in `GitHub #313 <https://github.com/ThreeMammals/Ocelot/issues/313>`_.

If you want to add a header to your upstream request please add the following to a ReRoute in your ocelot.json:

.. code-block:: json
"UpstreamHeaderTransform": {
"Uncle": "Bob"
}
In the example above a header with the key Uncle and value Bob would be send to to the upstream service.

Placeholders are supported too (see below).

Add to Response
^^^^^^^^^^^^^^^

This feature was requested in `GitHub #280 <https://github.com/TomPallister/Ocelot/issues/280>`_. I have only implemented
for responses but could add for requests in the future.
This feature was requested in `GitHub #280 <https://github.com/TomPallister/Ocelot/issues/280>`_.

If you want to add a header to your downstream response please add the following to a ReRoute in ocelot.json..

Expand Down Expand Up @@ -50,7 +66,7 @@ Add the following to a ReRoute in ocelot.json in order to replace http://www.bbc
},
Post Downstream Request
^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^

Add the following to a ReRoute in ocelot.json in order to replace http://www.bbc.co.uk/ with http://ocelot.com/. This transformation will take place after Ocelot has received the response from the downstream service.

Expand Down
11 changes: 10 additions & 1 deletion src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ public class DownstreamReRouteBuilder
private string _key;
private List<string> _delegatingHandlers;
private List<AddHeader> _addHeadersToDownstream;
private List<AddHeader> _addHeadersToUpstream;

public DownstreamReRouteBuilder()
{
_downstreamAddresses = new List<DownstreamHostAndPort>();
_delegatingHandlers = new List<string>();
_addHeadersToDownstream = new List<AddHeader>();
_addHeadersToUpstream = new List<AddHeader>();
}

public DownstreamReRouteBuilder WithDownstreamAddresses(List<DownstreamHostAndPort> downstreamAddresses)
Expand Down Expand Up @@ -233,6 +235,12 @@ public DownstreamReRouteBuilder WithAddHeadersToDownstream(List<AddHeader> addHe
return this;
}

public DownstreamReRouteBuilder WithAddHeadersToUpstream(List<AddHeader> addHeadersToUpstream)
{
_addHeadersToUpstream = addHeadersToUpstream;
return this;
}

public DownstreamReRoute Build()
{
return new DownstreamReRoute(
Expand Down Expand Up @@ -263,7 +271,8 @@ public DownstreamReRoute Build()
new PathTemplate(_downstreamPathTemplate),
_reRouteKey,
_delegatingHandlers,
_addHeadersToDownstream);
_addHeadersToDownstream,
_addHeadersToUpstream);
}
}
}
Loading

0 comments on commit b7ff737

Please sign in to comment.