Added a get authentication test, removed the infrastructure name space as it seemed pointless, started thinking about how to pass claims on with the request

This commit is contained in:
tom.pallister
2016-10-17 18:00:36 +01:00
parent ce84ad4fc2
commit 3d60602c7e
97 changed files with 614 additions and 508 deletions

View File

@ -0,0 +1,72 @@
namespace Ocelot.Library.RequestBuilder
{
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Responses;
public class HttpRequestBuilder : IRequestBuilder
{
public async Task<Response<Request>> Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers,
IRequestCookieCollection cookies, string queryString, string contentType)
{
var method = new HttpMethod(httpMethod);
var uri = new Uri(string.Format("{0}{1}", downstreamUrl, queryString));
var httpRequestMessage = new HttpRequestMessage(method, uri);
if (content != null)
{
using (var reader = new StreamReader(content))
{
var body = await reader.ReadToEndAsync();
httpRequestMessage.Content = new StringContent(body);
}
}
if (!string.IsNullOrEmpty(contentType))
{
var splitCt = contentType.Split(';');
var cT = splitCt[0];
httpRequestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue(cT);
}
//todo get rid of if
if (headers != null)
{
headers.Remove("Content-Type");
}
//todo get rid of if
if (headers != null)
{
foreach (var header in headers)
{
//todo get rid of if..
if (header.Key.ToLower() != "host")
{
httpRequestMessage.Headers.Add(header.Key, header.Value.ToArray());
}
}
}
var cookieContainer = new CookieContainer();
//todo get rid of if
if (cookies != null)
{
foreach (var cookie in cookies)
{
cookieContainer.Add(uri, new Cookie(cookie.Key, cookie.Value));
}
}
return new OkResponse<Request>(new Request(httpRequestMessage, cookieContainer));
}
}
}

View File

@ -0,0 +1,18 @@
namespace Ocelot.Library.RequestBuilder
{
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Responses;
public interface IRequestBuilder
{
Task<Response<Request>> Build(string httpMethod,
string downstreamUrl,
Stream content,
IHeaderDictionary headers,
IRequestCookieCollection cookies,
string queryString,
string contentType);
}
}

View File

@ -0,0 +1,17 @@
namespace Ocelot.Library.RequestBuilder
{
using System.Net;
using System.Net.Http;
public class Request
{
public Request(HttpRequestMessage httpRequestMessage, CookieContainer cookieContainer)
{
HttpRequestMessage = httpRequestMessage;
CookieContainer = cookieContainer;
}
public HttpRequestMessage HttpRequestMessage { get; private set; }
public CookieContainer CookieContainer { get; private set; }
}
}