Got the forwarding http content properly tests working, way to much going on in the requester

This commit is contained in:
TomPallister
2016-09-19 16:26:44 +01:00
parent f3128cffe0
commit 741fcc644d
5 changed files with 49 additions and 40 deletions

View File

@ -1,5 +1,6 @@
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Flurl;
using Flurl.Http;
@ -15,17 +16,30 @@ namespace Ocelot.Library.Infrastructure.Requester
Stream content,
IHeaderDictionary headers,
IRequestCookieCollection cookies,
IQueryCollection queryString)
IQueryCollection queryString,
string contentType)
{
var method = new HttpMethod(httpMethod);
var streamContent = new StreamContent(content);
if (!string.IsNullOrEmpty(contentType))
{
var splitCt = contentType.Split(';');
var cT = splitCt[0];
streamContent.Headers.ContentType = new MediaTypeHeaderValue(cT);
}
if (headers != null)
{
headers.Remove("Content-Type");
}
if (content.Length > 0)
{
return await downstreamUrl
.SetQueryParams(queryString)
.WithCookies(cookies)
.WithHeaders(streamContent.Headers)
.WithHeaders(headers)
.SendAsync(method, streamContent);
}

View File

@ -14,6 +14,7 @@ namespace Ocelot.Library.Infrastructure.Requester
Stream content,
IHeaderDictionary headers,
IRequestCookieCollection cookies,
IQueryCollection queryString);
IQueryCollection queryString,
string contentType);
}
}

View File

@ -49,7 +49,7 @@ namespace Ocelot.Library.Middleware
var response = await _requester
.GetResponse(context.Request.Method, downstreamUrl, context.Request.Body,
context.Request.Headers, context.Request.Cookies, context.Request.Query);
context.Request.Headers, context.Request.Cookies, context.Request.Query, context.Request.ContentType);
await _responder.CreateResponse(context, response);