change to catch not modified response and get config working correctly

This commit is contained in:
TomPallister
2017-02-25 17:47:24 +00:00
parent be24f9a9ca
commit a983af35a1
5 changed files with 52 additions and 37 deletions

View File

@ -86,13 +86,13 @@ namespace Ocelot.Configuration.Creator
var reRoutes = new List<ReRoute>();
foreach (var reRoute in _options.Value.ReRoutes)
foreach (var reRoute in fileConfiguration.ReRoutes)
{
var ocelotReRoute = await SetUpReRoute(reRoute, _options.Value.GlobalConfiguration);
var ocelotReRoute = await SetUpReRoute(reRoute, fileConfiguration.GlobalConfiguration);
reRoutes.Add(ocelotReRoute);
}
return new OcelotConfiguration(reRoutes, _options.Value.GlobalConfiguration.AdministrationPath);
return new OcelotConfiguration(reRoutes, fileConfiguration.GlobalConfiguration.AdministrationPath);
}
private async Task<ReRoute> SetUpReRoute(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration)

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using IdentityServer4.AccessTokenValidation;
using IdentityServer4.Models;
using Ocelot.Configuration.Provider;
namespace Ocelot.Configuration.Creator
{
public static class IdentityServerConfigurationCreator
{
public static IdentityServerConfiguration GetIdentityServerConfiguration()
{
var username = Environment.GetEnvironmentVariable("OCELOT_USERNAME");
var hash = Environment.GetEnvironmentVariable("OCELOT_HASH");
var salt = Environment.GetEnvironmentVariable("OCELOT_SALT");
return new IdentityServerConfiguration(
"admin",
false,
SupportedTokens.Both,
"secret",
new List<string> { "admin", "openid", "offline_access" },
"Ocelot Administration",
true,
GrantTypes.ResourceOwnerPassword,
AccessTokenType.Jwt,
false,
new List<User>
{
new User("admin", username, hash, salt)
}
);
}
}
}

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using CacheManager.Core;
using IdentityServer4.AccessTokenValidation;
using IdentityServer4.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
@ -61,7 +60,7 @@ namespace Ocelot.DependencyInjection
services.AddSingleton<IConfigurationValidator, FileConfigurationValidator>();
services.AddSingleton<IBaseUrlFinder, BaseUrlFinder>();
var identityServerConfiguration = GetIdentityServerConfiguration();
var identityServerConfiguration = IdentityServerConfigurationCreator.GetIdentityServerConfiguration();
if(identityServerConfiguration != null)
{
@ -142,29 +141,5 @@ namespace Ocelot.DependencyInjection
return services;
}
private static IdentityServerConfiguration GetIdentityServerConfiguration()
{
var username = Environment.GetEnvironmentVariable("OCELOT_USERNAME");
var hash = Environment.GetEnvironmentVariable("OCELOT_HASH");
var salt = Environment.GetEnvironmentVariable("OCELOT_SALT");
return new IdentityServerConfiguration(
"admin",
false,
SupportedTokens.Both,
"secret",
new List<string> {"admin", "openid", "offline_access"},
"Ocelot Administration",
true,
GrantTypes.ResourceOwnerPassword,
AccessTokenType.Jwt,
false,
new List<User>
{
new User("admin", username, hash, salt)
}
);
}
}
}

View File

@ -1,5 +1,6 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
@ -54,7 +55,10 @@ namespace Ocelot.Responder
using (Stream stream = new MemoryStream(content))
{
await stream.CopyToAsync(context.Response.Body);
if (response.StatusCode != HttpStatusCode.NotModified)
{
await stream.CopyToAsync(context.Response.Body);
}
}
}