mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 15:28:16 +08:00
Got the forwarding http content properly tests working, way to much going on in the requester
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ namespace Ocelot.Library.Infrastructure.Requester
|
||||
Stream content,
|
||||
IHeaderDictionary headers,
|
||||
IRequestCookieCollection cookies,
|
||||
IQueryCollection queryString);
|
||||
IQueryCollection queryString,
|
||||
string contentType);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user