Merge pull request #59 from TomPallister/feature/remove-cookie-container

Remove use of CookieContainer
This commit is contained in:
Tom Pallister 2017-03-06 02:28:48 +00:00 committed by GitHub
commit 5690d17310
12 changed files with 344 additions and 392 deletions

View File

@ -14,7 +14,6 @@ namespace Ocelot.Request.Builder
string downstreamUrl, string downstreamUrl,
Stream content, Stream content,
IHeaderDictionary headers, IHeaderDictionary headers,
IRequestCookieCollection cookies,
QueryString queryString, QueryString queryString,
string contentType, string contentType,
RequestId.RequestId requestId, RequestId.RequestId requestId,
@ -29,7 +28,6 @@ namespace Ocelot.Request.Builder
.WithContentType(contentType) .WithContentType(contentType)
.WithHeaders(headers) .WithHeaders(headers)
.WithRequestId(requestId) .WithRequestId(requestId)
.WithCookies(cookies)
.WithIsQos(isQos) .WithIsQos(isQos)
.WithQos(qosProvider) .WithQos(qosProvider)
.Build(); .Build();

View File

@ -12,7 +12,6 @@ namespace Ocelot.Request.Builder
string downstreamUrl, string downstreamUrl,
Stream content, Stream content,
IHeaderDictionary headers, IHeaderDictionary headers,
IRequestCookieCollection cookies,
QueryString queryString, QueryString queryString,
string contentType, string contentType,
RequestId.RequestId requestId, RequestId.RequestId requestId,

View File

@ -21,7 +21,6 @@ namespace Ocelot.Request.Builder
private string _contentType; private string _contentType;
private IHeaderDictionary _headers; private IHeaderDictionary _headers;
private RequestId.RequestId _requestId; private RequestId.RequestId _requestId;
private IRequestCookieCollection _cookies;
private readonly string[] _unsupportedHeaders = {"host"}; private readonly string[] _unsupportedHeaders = {"host"};
private bool _isQos; private bool _isQos;
private IQoSProvider _qoSProvider; private IQoSProvider _qoSProvider;
@ -68,12 +67,6 @@ namespace Ocelot.Request.Builder
return this; return this;
} }
public RequestBuilder WithCookies(IRequestCookieCollection cookies)
{
_cookies = cookies;
return this;
}
public RequestBuilder WithIsQos(bool isqos) public RequestBuilder WithIsQos(bool isqos)
{ {
_isQos = isqos; _isQos = isqos;
@ -103,9 +96,7 @@ namespace Ocelot.Request.Builder
AddRequestIdHeader(_requestId, httpRequestMessage); AddRequestIdHeader(_requestId, httpRequestMessage);
} }
var cookieContainer = CreateCookieContainer(uri); return new Request(httpRequestMessage,_isQos, _qoSProvider);
return new Request(httpRequestMessage, cookieContainer,_isQos, _qoSProvider);
} }
private Uri CreateUri() private Uri CreateUri()
@ -153,21 +144,6 @@ namespace Ocelot.Request.Builder
return !_unsupportedHeaders.Contains(header.Key.ToLower()); return !_unsupportedHeaders.Contains(header.Key.ToLower());
} }
private CookieContainer CreateCookieContainer(Uri uri)
{
var cookieContainer = new CookieContainer();
if (_cookies != null)
{
foreach (var cookie in _cookies)
{
cookieContainer.Add(uri, new Cookie(cookie.Key, cookie.Value));
}
}
return cookieContainer;
}
private void AddRequestIdHeader(RequestId.RequestId requestId, HttpRequestMessage httpRequestMessage) private void AddRequestIdHeader(RequestId.RequestId requestId, HttpRequestMessage httpRequestMessage)
{ {
httpRequestMessage.Headers.Add(requestId.RequestIdKey, requestId.RequestIdValue); httpRequestMessage.Headers.Add(requestId.RequestIdKey, requestId.RequestIdValue);

View File

@ -48,7 +48,6 @@ namespace Ocelot.Request.Middleware
DownstreamUrl, DownstreamUrl,
context.Request.Body, context.Request.Body,
context.Request.Headers, context.Request.Headers,
context.Request.Cookies,
context.Request.QueryString, context.Request.QueryString,
context.Request.ContentType, context.Request.ContentType,
new RequestId.RequestId(DownstreamRoute?.ReRoute?.RequestIdKey, context.TraceIdentifier), new RequestId.RequestId(DownstreamRoute?.ReRoute?.RequestIdKey, context.TraceIdentifier),

View File

@ -1,7 +1,4 @@
using Ocelot.Configuration; using System.Net.Http;
using Ocelot.Values;
using System.Net;
using System.Net.Http;
using Ocelot.Requester.QoS; using Ocelot.Requester.QoS;
namespace Ocelot.Request namespace Ocelot.Request
@ -10,18 +7,15 @@ namespace Ocelot.Request
{ {
public Request( public Request(
HttpRequestMessage httpRequestMessage, HttpRequestMessage httpRequestMessage,
CookieContainer cookieContainer,
bool isQos, bool isQos,
IQoSProvider qosProvider) IQoSProvider qosProvider)
{ {
HttpRequestMessage = httpRequestMessage; HttpRequestMessage = httpRequestMessage;
CookieContainer = cookieContainer;
IsQos = isQos; IsQos = isQos;
QosProvider = qosProvider; QosProvider = qosProvider;
} }
public HttpRequestMessage HttpRequestMessage { get; private set; } public HttpRequestMessage HttpRequestMessage { get; private set; }
public CookieContainer CookieContainer { get; private set; }
public bool IsQos { get; private set; } public bool IsQos { get; private set; }
public IQoSProvider QosProvider { get; private set; } public IQoSProvider QosProvider { get; private set; }
} }

View File

@ -11,17 +11,17 @@ namespace Ocelot.Requester
{ {
private readonly Dictionary<int, Func<DelegatingHandler>> _handlers = new Dictionary<int, Func<DelegatingHandler>>(); private readonly Dictionary<int, Func<DelegatingHandler>> _handlers = new Dictionary<int, Func<DelegatingHandler>>();
public HttpClientBuilder WithQoS(IQoSProvider qoSProvider, IOcelotLogger logger, HttpMessageHandler innerHandler) public HttpClientBuilder WithQoS(IQoSProvider qoSProvider, IOcelotLogger logger)
{ {
_handlers.Add(5000, () => new PollyCircuitBreakingDelegatingHandler(qoSProvider, logger, innerHandler)); _handlers.Add(5000, () => new PollyCircuitBreakingDelegatingHandler(qoSProvider, logger));
return this; return this;
} }
internal HttpClient Build(HttpMessageHandler innerHandler) internal HttpClient Build()
{ {
return _handlers.Any() ? return _handlers.Any() ?
new HttpClient(CreateHttpMessageHandler()) : new HttpClient(CreateHttpMessageHandler()) :
new HttpClient(innerHandler); new HttpClient();
} }
private HttpMessageHandler CreateHttpMessageHandler() private HttpMessageHandler CreateHttpMessageHandler()

View File

@ -21,34 +21,31 @@ namespace Ocelot.Requester
{ {
var builder = new HttpClientBuilder(); var builder = new HttpClientBuilder();
using (var handler = new HttpClientHandler { CookieContainer = request.CookieContainer }) if (request.IsQos)
{ {
if (request.IsQos) builder.WithQoS(request.QosProvider, _logger);
{ }
builder.WithQoS(request.QosProvider, _logger, handler);
}
using (var httpClient = builder.Build(handler)) using (var httpClient = builder.Build())
{
try
{ {
try var response = await httpClient.SendAsync(request.HttpRequestMessage);
{ return new OkResponse<HttpResponseMessage>(response);
var response = await httpClient.SendAsync(request.HttpRequestMessage); }
return new OkResponse<HttpResponseMessage>(response); catch (TimeoutRejectedException exception)
} {
catch (TimeoutRejectedException exception) return
{ new ErrorResponse<HttpResponseMessage>(new RequestTimedOutError(exception));
return }
new ErrorResponse<HttpResponseMessage>(new RequestTimedOutError(exception)); catch (BrokenCircuitException exception)
} {
catch (BrokenCircuitException exception) return
{ new ErrorResponse<HttpResponseMessage>(new RequestTimedOutError(exception));
return }
new ErrorResponse<HttpResponseMessage>(new RequestTimedOutError(exception)); catch (Exception exception)
} {
catch (Exception exception) return new ErrorResponse<HttpResponseMessage>(new UnableToCompleteRequestError(exception));
{
return new ErrorResponse<HttpResponseMessage>(new UnableToCompleteRequestError(exception));
}
} }
} }
} }

View File

@ -16,9 +16,7 @@ namespace Ocelot.Requester
public PollyCircuitBreakingDelegatingHandler( public PollyCircuitBreakingDelegatingHandler(
IQoSProvider qoSProvider, IQoSProvider qoSProvider,
IOcelotLogger logger, IOcelotLogger logger)
HttpMessageHandler innerHandler)
: base(innerHandler)
{ {
_qoSProvider = qoSProvider; _qoSProvider = qoSProvider;
_logger = logger; _logger = logger;

View File

@ -1,303 +1,311 @@
{ {
"ReRoutes": [ "ReRoutes": [
{ {
"DownstreamPathTemplate": "/", "DownstreamPathTemplate": "/",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "localhost", "DownstreamHost": "localhost",
"DownstreamPort": 52876, "DownstreamPort": 52876,
"UpstreamPathTemplate": "/identityserverexample", "UpstreamPathTemplate": "/identityserverexample",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"AuthenticationOptions": { "AuthenticationOptions": {
"Provider": "IdentityServer", "Provider": "IdentityServer",
"ProviderRootUrl": "http://localhost:52888", "ProviderRootUrl": "http://localhost:52888",
"ScopeName": "api", "ScopeName": "api",
"AdditionalScopes": [ "AdditionalScopes": [
"openid", "openid",
"offline_access" "offline_access"
], ],
"ScopeSecret": "secret" "ScopeSecret": "secret"
}, },
"AddHeadersToRequest": { "AddHeadersToRequest": {
"CustomerId": "Claims[CustomerId] > value", "CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value", "LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |", "UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |" "UserId": "Claims[sub] > value[1] > |"
}, },
"AddClaimsToRequest": { "AddClaimsToRequest": {
"CustomerId": "Claims[CustomerId] > value", "CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value", "LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |", "UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |" "UserId": "Claims[sub] > value[1] > |"
}, },
"AddQueriesToRequest": { "AddQueriesToRequest": {
"CustomerId": "Claims[CustomerId] > value", "CustomerId": "Claims[CustomerId] > value",
"LocationId": "Claims[LocationId] > value", "LocationId": "Claims[LocationId] > value",
"UserType": "Claims[sub] > value[0] > |", "UserType": "Claims[sub] > value[0] > |",
"UserId": "Claims[sub] > value[1] > |" "UserId": "Claims[sub] > value[1] > |"
}, },
"RouteClaimsRequirement": { "RouteClaimsRequirement": {
"UserType": "registered" "UserType": "registered"
}, },
"RequestIdKey": "OcRequestId" "RequestIdKey": "OcRequestId"
}, },
{ {
"DownstreamPathTemplate": "/posts", "DownstreamPathTemplate": "/posts",
"DownstreamScheme": "https", "DownstreamScheme": "https",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 443, "DownstreamPort": 443,
"UpstreamPathTemplate": "/posts", "UpstreamPathTemplate": "/posts",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/posts/{postId}", "DownstreamPathTemplate": "/posts/{postId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts/{postId}", "UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/posts/{postId}/comments", "DownstreamPathTemplate": "/posts/{postId}/comments",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts/{postId}/comments", "UpstreamPathTemplate": "/posts/{postId}/comments",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/comments", "DownstreamPathTemplate": "/comments",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/comments", "UpstreamPathTemplate": "/comments",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/posts", "DownstreamPathTemplate": "/posts",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts", "UpstreamPathTemplate": "/posts",
"UpstreamHttpMethod": "Post", "UpstreamHttpMethod": "Post",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/posts/{postId}", "DownstreamPathTemplate": "/posts/{postId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts/{postId}", "UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Put", "UpstreamHttpMethod": "Put",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/posts/{postId}", "DownstreamPathTemplate": "/posts/{postId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts/{postId}", "UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Patch", "UpstreamHttpMethod": "Patch",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/posts/{postId}", "DownstreamPathTemplate": "/posts/{postId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts/{postId}", "UpstreamPathTemplate": "/posts/{postId}",
"UpstreamHttpMethod": "Delete", "UpstreamHttpMethod": "Delete",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/api/products", "DownstreamPathTemplate": "/api/products",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/products", "UpstreamPathTemplate": "/products",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/products/{productId}", "DownstreamPathTemplate": "/api/products/{productId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/products/{productId}", "UpstreamPathTemplate": "/products/{productId}",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/products", "DownstreamPathTemplate": "/api/products",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "products20161126090340.azurewebsites.net", "DownstreamHost": "products20161126090340.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/products", "UpstreamPathTemplate": "/products",
"UpstreamHttpMethod": "Post", "UpstreamHttpMethod": "Post",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
} }
}, },
{ {
"DownstreamPathTemplate": "/api/products/{productId}", "DownstreamPathTemplate": "/api/products/{productId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "products20161126090340.azurewebsites.net", "DownstreamHost": "products20161126090340.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/products/{productId}", "UpstreamPathTemplate": "/products/{productId}",
"UpstreamHttpMethod": "Put", "UpstreamHttpMethod": "Put",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/products/{productId}", "DownstreamPathTemplate": "/api/products/{productId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "products20161126090340.azurewebsites.net", "DownstreamHost": "products20161126090340.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/products/{productId}", "UpstreamPathTemplate": "/products/{productId}",
"UpstreamHttpMethod": "Delete", "UpstreamHttpMethod": "Delete",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/customers", "DownstreamPathTemplate": "/api/customers",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "customers20161126090811.azurewebsites.net", "DownstreamHost": "customers20161126090811.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/customers", "UpstreamPathTemplate": "/customers",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/customers/{customerId}", "DownstreamPathTemplate": "/api/customers/{customerId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "customers20161126090811.azurewebsites.net", "DownstreamHost": "customers20161126090811.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/customers/{customerId}", "UpstreamPathTemplate": "/customers/{customerId}",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/customers", "DownstreamPathTemplate": "/api/customers",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "customers20161126090811.azurewebsites.net", "DownstreamHost": "customers20161126090811.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/customers", "UpstreamPathTemplate": "/customers",
"UpstreamHttpMethod": "Post", "UpstreamHttpMethod": "Post",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/customers/{customerId}", "DownstreamPathTemplate": "/api/customers/{customerId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "customers20161126090811.azurewebsites.net", "DownstreamHost": "customers20161126090811.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/customers/{customerId}", "UpstreamPathTemplate": "/customers/{customerId}",
"UpstreamHttpMethod": "Put", "UpstreamHttpMethod": "Put",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/api/customers/{customerId}", "DownstreamPathTemplate": "/api/customers/{customerId}",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "customers20161126090811.azurewebsites.net", "DownstreamHost": "customers20161126090811.azurewebsites.net",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/customers/{customerId}", "UpstreamPathTemplate": "/customers/{customerId}",
"UpstreamHttpMethod": "Delete", "UpstreamHttpMethod": "Delete",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
}, },
{ {
"DownstreamPathTemplate": "/posts", "DownstreamPathTemplate": "/posts",
"DownstreamScheme": "http", "DownstreamScheme": "http",
"DownstreamHost": "jsonplaceholder.typicode.com", "DownstreamHost": "jsonplaceholder.typicode.com",
"DownstreamPort": 80, "DownstreamPort": 80,
"UpstreamPathTemplate": "/posts/", "UpstreamPathTemplate": "/posts/",
"UpstreamHttpMethod": "Get", "UpstreamHttpMethod": "Get",
"QoSOptions": { "QoSOptions": {
"ExceptionsAllowedBeforeBreaking": 3, "ExceptionsAllowedBeforeBreaking": 3,
"DurationOfBreak": 10, "DurationOfBreak": 10,
"TimeoutValue": 5000 "TimeoutValue": 5000
}, },
"FileCacheOptions": { "TtlSeconds": 15 } "FileCacheOptions": { "TtlSeconds": 15 }
} },
], {
"DownstreamPathTemplate": "/",
"DownstreamScheme": "http",
"DownstreamHost": "www.bbc.co.uk",
"DownstreamPort": 80,
"UpstreamPathTemplate": "/bbc/",
"UpstreamHttpMethod": "Get"
}
],
"GlobalConfiguration": { "GlobalConfiguration": {
"RequestIdKey": "OcRequestId", "RequestIdKey": "OcRequestId",

View File

@ -79,7 +79,7 @@ namespace Ocelot.UnitTests.Request
this.Given(x => x.GivenTheDownStreamUrlIs("any old string")) this.Given(x => x.GivenTheDownStreamUrlIs("any old string"))
.And(x => x.GivenTheQosProviderHouseReturns(new OkResponse<IQoSProvider>(new NoQoSProvider()))) .And(x => x.GivenTheQosProviderHouseReturns(new OkResponse<IQoSProvider>(new NoQoSProvider())))
.And(x => x.GivenTheDownStreamRouteIs(downstreamRoute)) .And(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
.And(x => x.GivenTheRequestBuilderReturns(new Ocelot.Request.Request(new HttpRequestMessage(), new CookieContainer(), true, new NoQoSProvider()))) .And(x => x.GivenTheRequestBuilderReturns(new Ocelot.Request.Request(new HttpRequestMessage(), true, new NoQoSProvider())))
.When(x => x.WhenICallTheMiddleware()) .When(x => x.WhenICallTheMiddleware())
.Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly()) .Then(x => x.ThenTheScopedDataRepositoryIsCalledCorrectly())
.BDDfy(); .BDDfy();
@ -105,7 +105,7 @@ namespace Ocelot.UnitTests.Request
_request = new OkResponse<Ocelot.Request.Request>(request); _request = new OkResponse<Ocelot.Request.Request>(request);
_requestBuilder _requestBuilder
.Setup(x => x.Build(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Stream>(), It.IsAny<IHeaderDictionary>(), .Setup(x => x.Build(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Stream>(), It.IsAny<IHeaderDictionary>(),
It.IsAny<IRequestCookieCollection>(), It.IsAny<QueryString>(), It.IsAny<string>(), It.IsAny<Ocelot.RequestId.RequestId>(),It.IsAny<bool>(), It.IsAny<IQoSProvider>())) It.IsAny<QueryString>(), It.IsAny<string>(), It.IsAny<Ocelot.RequestId.RequestId>(),It.IsAny<bool>(), It.IsAny<IQoSProvider>()))
.ReturnsAsync(_request); .ReturnsAsync(_request);
} }

View File

@ -195,23 +195,6 @@ namespace Ocelot.UnitTests.Request
_qoSProvider = qoSProvider; _qoSProvider = qoSProvider;
} }
[Fact]
public void should_use_cookies()
{
this.Given(x => x.GivenIHaveHttpMethod("GET"))
.And(x => x.GivenIHaveDownstreamUrl("http://www.bbc.co.uk"))
.And(x => x.GivenTheCookiesAre(new RequestCookieCollection(new Dictionary<string, string>
{
{ "TheCookie","Monster" }
})))
.When(x => x.WhenICreateARequest())
.And(x => x.ThenTheCorrectCookiesAreUsed(new RequestCookieCollection(new Dictionary<string, string>
{
{ "TheCookie","Monster" }
})))
.BDDfy();
}
[Fact] [Fact]
public void should_user_query_string() public void should_user_query_string()
{ {
@ -240,14 +223,14 @@ namespace Ocelot.UnitTests.Request
private void ThenTheCorrectCookiesAreUsed(IRequestCookieCollection expected) private void ThenTheCorrectCookiesAreUsed(IRequestCookieCollection expected)
{ {
var resultCookies = _result.Data.CookieContainer.GetCookies(new Uri(_downstreamUrl + _query)); /* var resultCookies = _result.Data.CookieContainer.GetCookies(new Uri(_downstreamUrl + _query));
var resultDictionary = resultCookies.Cast<Cookie>().ToDictionary(cook => cook.Name, cook => cook.Value); var resultDictionary = resultCookies.Cast<Cookie>().ToDictionary(cook => cook.Name, cook => cook.Value);
foreach (var expectedCookie in expected) foreach (var expectedCookie in expected)
{ {
var resultCookie = resultDictionary[expectedCookie.Key]; var resultCookie = resultDictionary[expectedCookie.Key];
resultCookie.ShouldBe(expectedCookie.Value); resultCookie.ShouldBe(expectedCookie.Value);
} }*/
} }
private void GivenTheCookiesAre(IRequestCookieCollection cookies) private void GivenTheCookiesAre(IRequestCookieCollection cookies)
@ -305,7 +288,7 @@ namespace Ocelot.UnitTests.Request
private void WhenICreateARequest() private void WhenICreateARequest()
{ {
_result = _requestCreator.Build(_httpMethod, _downstreamUrl, _content?.ReadAsStreamAsync().Result, _headers, _result = _requestCreator.Build(_httpMethod, _downstreamUrl, _content?.ReadAsStreamAsync().Result, _headers,
_cookies, _query, _contentType, _requestId,_isQos,_qoSProvider).Result; _query, _contentType, _requestId,_isQos,_qoSProvider).Result;
} }

View File

@ -62,7 +62,7 @@ namespace Ocelot.UnitTests.Requester
[Fact] [Fact]
public void should_call_scoped_data_repository_correctly() public void should_call_scoped_data_repository_correctly()
{ {
this.Given(x => x.GivenTheRequestIs(new Ocelot.Request.Request(new HttpRequestMessage(),new CookieContainer(),true, new NoQoSProvider()))) this.Given(x => x.GivenTheRequestIs(new Ocelot.Request.Request(new HttpRequestMessage(),true, new NoQoSProvider())))
.And(x => x.GivenTheRequesterReturns(new HttpResponseMessage())) .And(x => x.GivenTheRequesterReturns(new HttpResponseMessage()))
.And(x => x.GivenTheScopedRepoReturns()) .And(x => x.GivenTheScopedRepoReturns())
.When(x => x.WhenICallTheMiddleware()) .When(x => x.WhenICallTheMiddleware())