-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support has been added for X-Forwarded-Port and X-Forwarded-Proto. This will enable reverse proxy servers to feed the public port and protocol to eventstore. These values will be used in generating URLs in responses.
- Loading branch information
Showing
6 changed files
with
98 additions
and
2 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
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"; | ||
} | ||
} |