mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 00:58:15 +08:00
failing pesky test
This commit is contained in:
@ -1,17 +1,39 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Requester
|
||||
{
|
||||
public class HttpClientHttpRequester : IHttpRequester
|
||||
{
|
||||
public async Task<HttpResponseMessage> GetResponse(string httpMethod, string downstreamUrl, Stream content = null)
|
||||
public async Task<HttpResponseMessage> GetResponse(
|
||||
string httpMethod,
|
||||
string downstreamUrl,
|
||||
Stream content,
|
||||
IHeaderDictionary headers,
|
||||
IRequestCookieCollection cookies,
|
||||
IQueryCollection queryString)
|
||||
{
|
||||
var method = new HttpMethod(httpMethod);
|
||||
var streamContent = new StreamContent(content);
|
||||
|
||||
return await downstreamUrl.SendAsync(method, new StreamContent(content));
|
||||
if (content.Length > 0)
|
||||
{
|
||||
return await downstreamUrl
|
||||
.SetQueryParams(queryString)
|
||||
.WithCookies(cookies)
|
||||
.WithHeaders(streamContent.Headers)
|
||||
.SendAsync(method, streamContent);
|
||||
}
|
||||
|
||||
return await downstreamUrl
|
||||
.SetQueryParams(queryString)
|
||||
.WithHeaders(headers)
|
||||
.WithCookies(cookies)
|
||||
.SendAsync(method, streamContent);
|
||||
}
|
||||
}
|
||||
}
|
@ -2,11 +2,18 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Requester
|
||||
{
|
||||
public interface IHttpRequester
|
||||
{
|
||||
Task<HttpResponseMessage> GetResponse(string httpMethod, string downstreamUrl, Stream content = null);
|
||||
Task<HttpResponseMessage> GetResponse(
|
||||
string httpMethod,
|
||||
string downstreamUrl,
|
||||
Stream content,
|
||||
IHeaderDictionary headers,
|
||||
IRequestCookieCollection cookies,
|
||||
IQueryCollection queryString);
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,9 @@ namespace Ocelot.Library.Middleware
|
||||
|
||||
var downstreamUrl = _urlReplacer.ReplaceTemplateVariables(downstreamRoute.Data);
|
||||
|
||||
var response = await _requester.GetResponse(context.Request.Method, downstreamUrl, context.Request.Body);
|
||||
var response = await _requester
|
||||
.GetResponse(context.Request.Method, downstreamUrl, context.Request.Body,
|
||||
context.Request.Headers, context.Request.Cookies, context.Request.Query);
|
||||
|
||||
await _responder.CreateResponse(context, response);
|
||||
|
||||
|
Reference in New Issue
Block a user