Skip to content

Commit ce652c0

Browse files
Consider the scheme in the unit test.
1 parent ca8045d commit ce652c0

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

dotnet/test/DotNetCoreWebUnitTest/Middleware/HeadersTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ public async Task TestForwardedHeaders()
1717
{
1818
const string host = "192.168.1.100";
1919
const string scheme = "https";
20+
const string remoteUrl = $"{scheme}:\\/\\/{host}";
2021
HttpClient client = server.CreateClient();
2122
client.DefaultRequestHeaders.Add("X-Forwarded-For", host);
2223
client.DefaultRequestHeaders.Add("X-Forwarded-Proto", scheme);
2324

2425
HttpResponseMessage response = await client.GetAsync("/rest/apps/httpheaders");
2526
response.EnsureSuccessStatusCode();
2627
string resp = await response.Content.ReadAsStringAsync();
27-
Assert.Contains(host, resp, System.StringComparison.OrdinalIgnoreCase);
28+
Assert.Contains(remoteUrl, resp, System.StringComparison.OrdinalIgnoreCase);
2829
Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);
2930
}
31+
3032
}
3133
}

dotnet/test/DotNetCoreWebUnitTest/apps/httpheaders.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void execute(out string result)
2929

3030
void executePrivate(out string result)
3131
{
32-
result = context.GetRemoteAddress();
32+
result = (context.GetHttpSecure() == 1 ? "https://" : "http://") + context.GetRemoteAddress();
3333

3434
cleanup();
3535
}

0 commit comments

Comments
 (0)