mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-12-24 21:15:49 +08:00
ripping out flurl...sorry flurl
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
namespace Ocelot.Library.Infrastructure.RequestBuilder
|
||||
{
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
public interface IRequestBuilder
|
||||
{
|
||||
HttpRequestMessage Build(string httpMethod,
|
||||
string downstreamUrl,
|
||||
Stream content,
|
||||
IHeaderDictionary headers,
|
||||
IRequestCookieCollection cookies,
|
||||
IQueryCollection queryString,
|
||||
string contentType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
namespace Ocelot.Library.Infrastructure.RequestBuilder
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
public class RequestBuilder : IRequestBuilder
|
||||
{
|
||||
public HttpRequestMessage Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers,
|
||||
IRequestCookieCollection cookies, IQueryCollection queryString, string contentType)
|
||||
{
|
||||
var method = new HttpMethod(httpMethod);
|
||||
|
||||
var uri = new Uri(downstreamUrl + queryString);
|
||||
|
||||
var httpRequestMessage = new HttpRequestMessage(method, uri)
|
||||
{
|
||||
Content = new StreamContent(content),
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
httpRequestMessage.Headers.Add(header.Key, header.Value.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
return httpRequestMessage;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user