made a response middlware as terminating middleware...

This commit is contained in:
TomPallister
2016-10-08 09:59:37 +01:00
parent 3685efec05
commit a7a1143823
17 changed files with 165 additions and 86 deletions

View File

@@ -3,13 +3,14 @@ using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Infrastructure.RequestBuilder
{
public class RequestBuilder : IRequestBuilder
public class HttpRequestBuilder : IRequestBuilder
{
public Request Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers,
public async Task<Request> Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers,
IRequestCookieCollection cookies, string queryString, string contentType)
{
var method = new HttpMethod(httpMethod);
@@ -20,7 +21,11 @@ namespace Ocelot.Library.Infrastructure.RequestBuilder
if (content != null)
{
httpRequestMessage.Content = new StreamContent(content);
using (var reader = new StreamReader(content))
{
var body = await reader.ReadToEndAsync();
httpRequestMessage.Content = new StringContent(body);
}
}
if (!string.IsNullOrEmpty(contentType))
@@ -41,7 +46,11 @@ namespace Ocelot.Library.Infrastructure.RequestBuilder
{
foreach (var header in headers)
{
httpRequestMessage.Headers.Add(header.Key, header.Value.ToArray());
//todo get rid of if..
if (header.Key.ToLower() != "host")
{
httpRequestMessage.Headers.Add(header.Key, header.Value.ToArray());
}
}
}

View File

@@ -1,11 +1,12 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Infrastructure.RequestBuilder
{
public interface IRequestBuilder
{
Request Build(string httpMethod,
Task<Request> Build(string httpMethod,
string downstreamUrl,
Stream content,
IHeaderDictionary headers,