Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from adbrowne/reverseproxy
Support for X-Forwarded headers
- Loading branch information
Showing
7 changed files
with
102 additions
and
11 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
55 changes: 55 additions & 0 deletions
55
src/EventStore.Core.Tests/Services/Transport/Http/proxy_headers.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,55 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using EventStore.Transport.Http.EntityManagement; | ||
using NUnit.Framework; | ||
|
||
namespace EventStore.Core.Tests.Services.Transport.Http | ||
{ | ||
[TestFixture] | ||
class proxy_headers | ||
{ | ||
[Test] | ||
public void with_no_headers_uri_is_unchanged() | ||
{ | ||
var inputUri = new Uri("http://www.example.com:1234/path/?key=value#anchor"); | ||
var requestedUri = | ||
HttpEntity.BuildRequestedUrl(inputUri, | ||
new NameValueCollection()); | ||
|
||
Assert.AreEqual(inputUri, requestedUri); | ||
} | ||
|
||
[Test] | ||
public void with_port_forward_header_only_port_is_changed() | ||
{ | ||
var inputUri = new Uri("http://www.example.com:1234/path/?key=value#anchor"); | ||
var headers = new NameValueCollection { { "X-Forwarded-Port", "4321" } }; | ||
var requestedUri = | ||
HttpEntity.BuildRequestedUrl(inputUri, headers); | ||
|
||
Assert.AreEqual(new Uri("http://www.example.com:4321/path/?key=value#anchor"), requestedUri); | ||
} | ||
|
||
[Test] | ||
public void non_integer_port_forward_header_is_ignored() | ||
{ | ||
var inputUri = new Uri("http://www.example.com:1234/path/?key=value#anchor"); | ||
var headers = new NameValueCollection { { "X-Forwarded-Port", "abc" } }; | ||
var requestedUri = | ||
HttpEntity.BuildRequestedUrl(inputUri, headers); | ||
|
||
Assert.AreEqual(inputUri, requestedUri); | ||
} | ||
|
||
[Test] | ||
public void with_proto_forward_header_only_scheme_is_changed() | ||
{ | ||
var inputUri = new Uri("http://www.example.com:1234/path/?key=value#anchor"); | ||
var headers = new NameValueCollection { { "X-Forwarded-Proto", "https" } }; | ||
var requestedUri = | ||
HttpEntity.BuildRequestedUrl(inputUri, headers); | ||
|
||
Assert.AreEqual(new Uri("https://www.example.com:1234/path/?key=value#anchor"), requestedUri); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace EventStore.Transport.Http | ||
{ | ||
public static class ProxyHeaders | ||
{ | ||
public const string XForwardedPort = "X-Forwarded-Port"; | ||
public const string XForwardedProto = "X-Forwarded-Proto"; | ||
} | ||
|
||
public static class ProxyHeaderValues | ||
{ | ||
public const string XForwardedProtoHttp = "http"; | ||
public const string XForwardedProtoHttps = "https"; | ||
} | ||
} |