mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 18:48:15 +08:00
Feature/proxy reason phrase (#618)
* #599 started work to proxy reason phrase * #599 test for aggregator
This commit is contained in:
@ -559,7 +559,7 @@ namespace Ocelot.AcceptanceTests
|
||||
var merge = $"{one}, {two}";
|
||||
merge = merge.Replace("Hello", "Bye").Replace("{", "").Replace("}", "");
|
||||
var headers = responses.SelectMany(x => x.Headers).ToList();
|
||||
return new DownstreamResponse(new StringContent(merge), HttpStatusCode.OK, headers);
|
||||
return new DownstreamResponse(new StringContent(merge), HttpStatusCode.OK, headers, "some reason");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
76
test/Ocelot.AcceptanceTests/ReasonPhraseTests.cs
Normal file
76
test/Ocelot.AcceptanceTests/ReasonPhraseTests.cs
Normal file
@ -0,0 +1,76 @@
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Ocelot.Configuration.File;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
public class ReasonPhraseTests : IDisposable
|
||||
{
|
||||
private readonly Steps _steps;
|
||||
private string _contentType;
|
||||
private long? _contentLength;
|
||||
private bool _contentTypeHeaderExists;
|
||||
private readonly ServiceHandler _serviceHandler;
|
||||
|
||||
public ReasonPhraseTests()
|
||||
{
|
||||
_serviceHandler = new ServiceHandler();
|
||||
_steps = new Steps();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_reason_phrase()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamPathTemplate = "/",
|
||||
DownstreamScheme = "http",
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "localhost",
|
||||
Port = 51339,
|
||||
}
|
||||
},
|
||||
UpstreamPathTemplate = "/",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51339", "/", "some reason"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
|
||||
.And(_ => _steps.ThenTheReasonPhraseIs("some reason"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, string reasonPhrase)
|
||||
{
|
||||
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, async context =>
|
||||
{
|
||||
context.Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = reasonPhrase;
|
||||
|
||||
await context.Response.WriteAsync("YOYO!");
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_serviceHandler?.Dispose();
|
||||
_steps.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -452,6 +452,11 @@
|
||||
header.First().ShouldBe(value);
|
||||
}
|
||||
|
||||
public void ThenTheReasonPhraseIs(string expected)
|
||||
{
|
||||
_response.ReasonPhrase.ShouldBe(expected);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user