Commit 53a57610 authored by justcoding121's avatar justcoding121

#153

Demo how to share items accross same session
parent fc7e798c
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Titanium.Web.Proxy.EventArguments;
......@@ -10,10 +11,14 @@ namespace Titanium.Web.Proxy.Examples.Basic
{
private ProxyServer proxyServer;
//share requestBody outside handlers
private Dictionary<Guid, string> requestBodyHistory;
public ProxyTestController()
{
proxyServer = new ProxyServer();
proxyServer.TrustRootCertificate = true;
requestBodyHistory = new Dictionary<Guid, string>();
}
public void StartProxy()
......@@ -90,6 +95,7 @@ namespace Titanium.Web.Proxy.Examples.Basic
string bodyString = await e.GetRequestBodyAsString();
await e.SetRequestBodyString(bodyString);
requestBodyHistory[e.Id] = bodyString;
}
//To cancel a request with a custom HTML content
......@@ -114,6 +120,11 @@ namespace Titanium.Web.Proxy.Examples.Basic
//Modify response
public async Task OnResponse(object sender, SessionEventArgs e)
{
if(requestBodyHistory.ContainsKey(e.Id))
{
//access request body by looking up the shared dictionary using requestId
var requestBody = requestBodyHistory[e.Id];
}
//read response headers
var responseHeaders = e.WebSession.Response.ResponseHeaders;
......
......@@ -38,6 +38,12 @@ namespace Titanium.Web.Proxy.EventArguments
/// </summary>
internal ProxyClient ProxyClient { get; set; }
/// <summary>
/// Returns a unique Id for this request/response session
/// same as RequestId of WebSession
/// </summary>
public Guid Id => WebSession.RequestId;
//Should we send a rerequest
public bool ReRequest
{
......
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