Commit dd29dc75 authored by Jehonathan's avatar Jehonathan Committed by GitHub

Merge pull request #110 from TBulbaDB/master

Root Cert Name, Headers support for SessionEventArgs.Ok()
parents cdf61217 b1e64102
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using Titanium.Web.Proxy.Exceptions; using Titanium.Web.Proxy.Exceptions;
...@@ -9,6 +10,7 @@ using Titanium.Web.Proxy.Extensions; ...@@ -9,6 +10,7 @@ using Titanium.Web.Proxy.Extensions;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.Network; using Titanium.Web.Proxy.Network;
using System.Net; using System.Net;
using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.EventArguments namespace Titanium.Web.Proxy.EventArguments
{ {
...@@ -331,7 +333,6 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -331,7 +333,6 @@ namespace Titanium.Web.Proxy.EventArguments
return await decompressor.Decompress(responseBodyStream, bufferSize); return await decompressor.Decompress(responseBodyStream, bufferSize);
} }
/// <summary> /// <summary>
/// Before request is made to server /// Before request is made to server
/// Respond with the specified HTML string to client /// Respond with the specified HTML string to client
...@@ -339,6 +340,18 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -339,6 +340,18 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary> /// </summary>
/// <param name="html"></param> /// <param name="html"></param>
public async Task Ok(string html) public async Task Ok(string html)
{
await Ok(html, null);
}
/// <summary>
/// Before request is made to server
/// Respond with the specified HTML string to client
/// and ignore the request
/// </summary>
/// <param name="html"></param>
/// <param name="headers"></param>
public async Task Ok(string html, Dictionary<string, HttpHeader> headers)
{ {
if (WebSession.Request.RequestLocked) if (WebSession.Request.RequestLocked)
{ {
...@@ -352,7 +365,7 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -352,7 +365,7 @@ namespace Titanium.Web.Proxy.EventArguments
var result = Encoding.Default.GetBytes(html); var result = Encoding.Default.GetBytes(html);
await Ok(result); await Ok(result, headers);
} }
/// <summary> /// <summary>
...@@ -360,11 +373,26 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -360,11 +373,26 @@ namespace Titanium.Web.Proxy.EventArguments
/// Respond with the specified byte[] to client /// Respond with the specified byte[] to client
/// and ignore the request /// and ignore the request
/// </summary> /// </summary>
/// <param name="body"></param> /// <param name="result"></param>
public async Task Ok(byte[] result) public async Task Ok(byte[] result)
{ {
var response = new OkResponse(); await Ok(result, null);
}
/// <summary>
/// Before request is made to server
/// Respond with the specified byte[] to client
/// and ignore the request
/// </summary>
/// <param name="result"></param>
/// <param name="headers"></param>
public async Task Ok(byte[] result, Dictionary<string, HttpHeader> headers)
{
var response = new OkResponse();
if (headers != null && headers.Count > 0)
{
response.ResponseHeaders = headers;
}
response.HttpVersion = WebSession.Request.HttpVersion; response.HttpVersion = WebSession.Request.HttpVersion;
response.ResponseBody = result; response.ResponseBody = result;
......
...@@ -118,8 +118,12 @@ namespace Titanium.Web.Proxy ...@@ -118,8 +118,12 @@ namespace Titanium.Web.Proxy
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
public ProxyServer() public ProxyServer() : this(null, null) { }
public ProxyServer(string rootCertificateName, string rootCertificateIssuerName)
{ {
RootCertificateName = rootCertificateName;
RootCertificateIssuerName = rootCertificateIssuerName;
//default values //default values
ConnectionTimeOutSeconds = 120; ConnectionTimeOutSeconds = 120;
CertificateCacheTimeOutMinutes = 60; CertificateCacheTimeOutMinutes = 60;
...@@ -379,11 +383,11 @@ namespace Titanium.Web.Proxy ...@@ -379,11 +383,11 @@ namespace Titanium.Web.Proxy
} }
if (tcpClient != null) if (tcpClient != null)
{ {
Task.Run(async () => Task.Run(async () =>
{ {
try try
{ {
if (endPoint.GetType() == typeof(TransparentProxyEndPoint)) if (endPoint.GetType() == typeof(TransparentProxyEndPoint))
{ {
await HandleClient(endPoint as TransparentProxyEndPoint, tcpClient); await HandleClient(endPoint as TransparentProxyEndPoint, tcpClient);
...@@ -392,7 +396,7 @@ namespace Titanium.Web.Proxy ...@@ -392,7 +396,7 @@ namespace Titanium.Web.Proxy
{ {
await HandleClient(endPoint as ExplicitProxyEndPoint, tcpClient); await HandleClient(endPoint as ExplicitProxyEndPoint, tcpClient);
} }
} }
finally finally
{ {
......
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