Commit d85a2213 authored by justcoding121's avatar justcoding121

#280 demo how headers can be kept for later use

parent 6178e0c9
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Threading.Tasks; using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments; using Titanium.Web.Proxy.EventArguments;
using Titanium.Web.Proxy.Helpers; using Titanium.Web.Proxy.Helpers;
using Titanium.Web.Proxy.Http;
using Titanium.Web.Proxy.Models; using Titanium.Web.Proxy.Models;
namespace Titanium.Web.Proxy.Examples.Basic namespace Titanium.Web.Proxy.Examples.Basic
...@@ -13,6 +15,13 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -13,6 +15,13 @@ namespace Titanium.Web.Proxy.Examples.Basic
{ {
private readonly ProxyServer proxyServer; private readonly ProxyServer proxyServer;
//keep track of request headers
private readonly IDictionary<Guid, HeaderCollection> requestHeaderHistory = new ConcurrentDictionary<Guid, HeaderCollection>();
//keep track of response headers
private readonly IDictionary<Guid, HeaderCollection> responseHeaderHistory = new ConcurrentDictionary<Guid, HeaderCollection>();
//share requestBody outside handlers //share requestBody outside handlers
//Using a dictionary is not a good idea since it can cause memory overflow //Using a dictionary is not a good idea since it can cause memory overflow
//ideally the data should be moved out of memory //ideally the data should be moved out of memory
...@@ -136,7 +145,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -136,7 +145,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
Console.WriteLine(e.WebSession.Request.Url); Console.WriteLine(e.WebSession.Request.Url);
//read request headers //read request headers
var requestHeaders = e.WebSession.Request.RequestHeaders; requestHeaderHistory[e.Id] = e.WebSession.Request.RequestHeaders;
if (e.WebSession.Request.HasBody) if (e.WebSession.Request.HasBody)
{ {
...@@ -183,7 +192,7 @@ namespace Titanium.Web.Proxy.Examples.Basic ...@@ -183,7 +192,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
//} //}
//read response headers //read response headers
var responseHeaders = e.WebSession.Response.ResponseHeaders; responseHeaderHistory[e.Id] = e.WebSession.Response.ResponseHeaders;
// print out process id of current session // print out process id of current session
//Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}"); //Console.WriteLine($"PID: {e.WebSession.ProcessId.Value}");
......
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