mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
merged develop
This commit is contained in:
parent
0421dba1e2
commit
c41dd950e0
@ -8,6 +8,8 @@ using Ocelot.Library.Infrastructure.UrlPathTemplateRepository;
|
||||
|
||||
namespace Ocelot.Library.Middleware
|
||||
{
|
||||
using System.Net;
|
||||
|
||||
public class ProxyMiddleware
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
@ -49,9 +51,10 @@ namespace Ocelot.Library.Middleware
|
||||
}
|
||||
}
|
||||
|
||||
if (!urlPathMatch.Match)
|
||||
if (urlPathMatch == null || !urlPathMatch.Match)
|
||||
{
|
||||
throw new Exception("BOOOM TING! no match");
|
||||
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
return;
|
||||
}
|
||||
|
||||
var upstreamHostUrl = _hostUrlRepository.GetBaseUrlMap(urlPathMatch.DownstreamUrlPathTemplate);
|
||||
|
@ -8,6 +8,11 @@ using Ocelot.Library.Middleware;
|
||||
|
||||
namespace Ocelot
|
||||
{
|
||||
using Library.Infrastructure.HostUrlRepository;
|
||||
using Library.Infrastructure.UrlPathMatcher;
|
||||
using Library.Infrastructure.UrlPathReplacer;
|
||||
using Library.Infrastructure.UrlPathTemplateRepository;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
@ -26,7 +31,11 @@ namespace Ocelot
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add framework services.
|
||||
|
||||
services.AddSingleton<IHostUrlMapRepository, InMemoryHostUrlMapRepository>();
|
||||
services.AddSingleton<IUrlPathToUrlPathTemplateMatcher, UrlPathToUrlPathTemplateMatcher>();
|
||||
services.AddSingleton<IHostUrlMapRepository, InMemoryHostUrlMapRepository>();
|
||||
services.AddSingleton<IUpstreamUrlPathTemplateVariableReplacer, UpstreamUrlPathTemplateVariableReplacer>();
|
||||
services.AddSingleton<IUrlPathTemplateMapRepository, InMemoryUrlPathTemplateMapRepository>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
@ -37,11 +46,6 @@ namespace Ocelot
|
||||
loggerFactory.AddDebug();
|
||||
|
||||
app.UseProxy();
|
||||
//app.Run()
|
||||
// app.Run(async context =>
|
||||
// {
|
||||
// await context.Response.WriteAsync("Hello from Tom");
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Xunit;
|
||||
@ -9,41 +8,40 @@ using Shouldly;
|
||||
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using System.Net;
|
||||
|
||||
public class RouterTests : IDisposable
|
||||
{
|
||||
private FakeService _fakeService;
|
||||
private readonly FakeService _fakeService;
|
||||
private readonly TestServer _server;
|
||||
private readonly HttpClient _client;
|
||||
private HttpResponseMessage _response;
|
||||
|
||||
public RouterTests()
|
||||
{
|
||||
_server = new TestServer(new WebHostBuilder()
|
||||
.UseStartup<Startup>());
|
||||
|
||||
_client = _server.CreateClient();
|
||||
|
||||
_fakeService = new FakeService();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void hello_world()
|
||||
public void should_return_response_404()
|
||||
{
|
||||
var response = _client.GetAsync("/").Result;
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseString = response.Content.ReadAsStringAsync().Result;
|
||||
responseString.ShouldBe("Hello from Tom");
|
||||
WhenIRequestTheUrl("/");
|
||||
ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task can_route_request()
|
||||
private void WhenIRequestTheUrl(string url)
|
||||
{
|
||||
_fakeService.Start("http://localhost:5001");
|
||||
_response = _client.GetAsync("/").Result;
|
||||
}
|
||||
|
||||
// Act
|
||||
var response = await _client.GetAsync("/");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var responseString = await response.Content.ReadAsStringAsync();
|
||||
responseString.ShouldBe("Hello from Laura");
|
||||
private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode)
|
||||
{
|
||||
_response.StatusCode.ShouldBe(expectedHttpStatusCode);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -15,6 +15,6 @@ GarbageCollection=Concurrent Workstation
|
||||
|
||||
```
|
||||
Method | Median | StdDev | Mean | StdError | StdDev | Op/s | Min | Q1 | Median | Q3 | Max |
|
||||
----------- |------------ |---------- |------------ |---------- |---------- |----------- |------------ |------------ |------------ |------------ |------------ |
|
||||
Benchmark1 | 180.4251 ns | 4.1294 ns | 180.4400 ns | 0.9234 ns | 4.1294 ns | 5542007.02 | 174.5503 ns | 177.6286 ns | 180.4251 ns | 182.5334 ns | 190.9792 ns |
|
||||
Benchmark2 | 178.7267 ns | 6.1670 ns | 180.6081 ns | 1.3148 ns | 6.1670 ns | 5536849.8 | 174.0821 ns | 177.0992 ns | 178.7267 ns | 182.1962 ns | 198.1308 ns |
|
||||
----------- |------------ |----------- |------------ |---------- |----------- |----------- |------------ |------------ |------------ |------------ |------------ |
|
||||
Benchmark1 | 184.4215 ns | 5.1537 ns | 185.3322 ns | 1.1524 ns | 5.1537 ns | 5395716.74 | 178.2386 ns | 181.8117 ns | 184.4215 ns | 188.2762 ns | 196.7310 ns |
|
||||
Benchmark2 | 186.1899 ns | 35.7006 ns | 202.4315 ns | 3.9425 ns | 35.7006 ns | 4939943.34 | 176.9750 ns | 182.9672 ns | 186.1899 ns | 205.8946 ns | 369.0701 ns |
|
||||
|
@ -1,3 +1,3 @@
|
||||
Type;Method;Mode;Platform;Jit;Toolchain;Runtime;GarbageCollection;LaunchCount;WarmupCount;TargetCount;Affinity;Median;StdDev;Mean;StdError;StdDev;Op/s;Min;Q1;Median;Q3;Max
|
||||
UrlPathToUrlPathTemplateMatcherBenchmarks;Benchmark1;Throughput;Host;Host;Core;Host;Concurrent Workstation;Auto;Auto;Auto;Auto;180.4251 ns;4.1294 ns;180.4400 ns;0.9234 ns;4.1294 ns;5542007.02;174.5503 ns;177.6286 ns;180.4251 ns;182.5334 ns;190.9792 ns
|
||||
UrlPathToUrlPathTemplateMatcherBenchmarks;Benchmark2;Throughput;Host;Host;Core;Host;Concurrent Workstation;Auto;Auto;Auto;Auto;178.7267 ns;6.1670 ns;180.6081 ns;1.3148 ns;6.1670 ns;5536849.8;174.0821 ns;177.0992 ns;178.7267 ns;182.1962 ns;198.1308 ns
|
||||
UrlPathToUrlPathTemplateMatcherBenchmarks;Benchmark1;Throughput;Host;Host;Core;Host;Concurrent Workstation;Auto;Auto;Auto;Auto;184.4215 ns;5.1537 ns;185.3322 ns;1.1524 ns;5.1537 ns;5395716.74;178.2386 ns;181.8117 ns;184.4215 ns;188.2762 ns;196.7310 ns
|
||||
UrlPathToUrlPathTemplateMatcherBenchmarks;Benchmark2;Throughput;Host;Host;Core;Host;Concurrent Workstation;Auto;Auto;Auto;Auto;186.1899 ns;35.7006 ns;202.4315 ns;3.9425 ns;35.7006 ns;4939943.34;176.9750 ns;182.9672 ns;186.1899 ns;205.8946 ns;369.0701 ns
|
||||
|
|
@ -15,6 +15,6 @@ GarbageCollection=Concurrent Workstation
|
||||
|
||||
<table>
|
||||
<tr><th>Method</th><th>Median</th><th>StdDev</th><th> Mean</th><th>StdError</th><th>StdDev</th><th>Op/s</th><th> Min</th><th> Q1</th><th>Median</th><th> Q3</th><th> Max</th>
|
||||
</tr><tr><td>Benchmark1</td><td>180.4251 ns</td><td>4.1294 ns</td><td>180.4400 ns</td><td>0.9234 ns</td><td>4.1294 ns</td><td>5542007.02</td><td>174.5503 ns</td><td>177.6286 ns</td><td>180.4251 ns</td><td>182.5334 ns</td><td>190.9792 ns</td>
|
||||
</tr><tr><td>Benchmark2</td><td>178.7267 ns</td><td>6.1670 ns</td><td>180.6081 ns</td><td>1.3148 ns</td><td>6.1670 ns</td><td>5536849.8</td><td>174.0821 ns</td><td>177.0992 ns</td><td>178.7267 ns</td><td>182.1962 ns</td><td>198.1308 ns</td>
|
||||
</tr><tr><td>Benchmark1</td><td>184.4215 ns</td><td>5.1537 ns</td><td>185.3322 ns</td><td>1.1524 ns</td><td>5.1537 ns</td><td>5395716.74</td><td>178.2386 ns</td><td>181.8117 ns</td><td>184.4215 ns</td><td>188.2762 ns</td><td>196.7310 ns</td>
|
||||
</tr><tr><td>Benchmark2</td><td>186.1899 ns</td><td>35.7006 ns</td><td>202.4315 ns</td><td>3.9425 ns</td><td>35.7006 ns</td><td>4939943.34</td><td>176.9750 ns</td><td>182.9672 ns</td><td>186.1899 ns</td><td>205.8946 ns</td><td>369.0701 ns</td>
|
||||
</tr></table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user