Commit 5f442f07 authored by Honfika's avatar Honfika

Allow to pass IEnumerable<HttpHeader> to Respond methods.

parent a17fe88b
......@@ -469,7 +469,20 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="html">HTML content to sent.</param>
/// <param name="headers">HTTP response headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void Ok(string html, Dictionary<string, HttpHeader>? headers = null,
public void Ok(string html, IDictionary<string, HttpHeader>? headers = null,
bool closeServerConnection = false)
{
Ok(html, headers?.Values, closeServerConnection);
}
/// <summary>
/// Before request is made to server respond with the specified HTML string to client
/// and ignore the request.
/// </summary>
/// <param name="html">HTML content to sent.</param>
/// <param name="headers">HTTP response headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void Ok(string html, IEnumerable<HttpHeader>? headers = null,
bool closeServerConnection = false)
{
var response = new OkResponse();
......@@ -491,7 +504,20 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="result">The html content bytes.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void Ok(byte[] result, Dictionary<string, HttpHeader>? headers = null,
public void Ok(byte[] result, IDictionary<string, HttpHeader>? headers = null,
bool closeServerConnection = false)
{
Ok(result, headers?.Values, closeServerConnection);
}
/// <summary>
/// Before request is made to server respond with the specified byte[] to client
/// and ignore the request.
/// </summary>
/// <param name="result">The html content bytes.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void Ok(byte[] result, IEnumerable<HttpHeader>? headers = null,
bool closeServerConnection = false)
{
var response = new OkResponse();
......@@ -512,7 +538,22 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="headers">The HTTP headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void GenericResponse(string html, HttpStatusCode status,
Dictionary<string, HttpHeader>? headers = null, bool closeServerConnection = false)
IDictionary<string, HttpHeader>? headers = null, bool closeServerConnection = false)
{
GenericResponse(html, status, headers?.Values, closeServerConnection);
}
/// <summary>
/// Before request is made to server 
/// respond with the specified HTML string and the specified status to client.
/// And then ignore the request. 
/// </summary>
/// <param name="html">The html content.</param>
/// <param name="status">The HTTP status code.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void GenericResponse(string html, HttpStatusCode status,
IEnumerable<HttpHeader>? headers = null, bool closeServerConnection = false)
{
var response = new GenericResponse(status);
response.HttpVersion = HttpClient.Request.HttpVersion;
......@@ -531,7 +572,21 @@ namespace Titanium.Web.Proxy.EventArguments
/// <param name="headers">The HTTP headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void GenericResponse(byte[] result, HttpStatusCode status,
Dictionary<string, HttpHeader> headers, bool closeServerConnection = false)
IDictionary<string, HttpHeader> headers, bool closeServerConnection = false)
{
GenericResponse(result, status, headers?.Values, closeServerConnection);
}
/// <summary>
/// Before request is made to server respond with the specified byte[],
/// the specified status to client. And then ignore the request.
/// </summary>
/// <param name="result">The bytes to sent.</param>
/// <param name="status">The HTTP status code.</param>
/// <param name="headers">The HTTP headers.</param>
/// <param name="closeServerConnection">Close the server connection used by request if any?</param>
public void GenericResponse(byte[] result, HttpStatusCode status,
IEnumerable<HttpHeader>? headers, bool closeServerConnection = false)
{
var response = new GenericResponse(status);
response.HttpVersion = HttpClient.Request.HttpVersion;
......
......@@ -160,16 +160,15 @@ namespace Titanium.Web.Proxy.Http
public void AddHeader(HttpHeader newHeader)
{
// if header exist in non-unique header collection add it there
if (nonUniqueHeaders.ContainsKey(newHeader.Name))
if (nonUniqueHeaders.TryGetValue(newHeader.Name, out var list))
{
nonUniqueHeaders[newHeader.Name].Add(newHeader);
list.Add(newHeader);
return;
}
// if header is already in unique header collection then move both to non-unique collection
if (headers.ContainsKey(newHeader.Name))
if (headers.TryGetValue(newHeader.Name, out var existing))
{
var existing = headers[newHeader.Name];
headers.Remove(newHeader.Name);
nonUniqueHeaders.Add(newHeader.Name, new List<HttpHeader>
......@@ -189,7 +188,7 @@ namespace Titanium.Web.Proxy.Http
/// Adds the given header objects to Request
/// </summary>
/// <param name="newHeaders"></param>
public void AddHeaders(IEnumerable<HttpHeader> newHeaders)
public void AddHeaders(IEnumerable<HttpHeader>? newHeaders)
{
if (newHeaders == null)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment