Commit 42a5ee99 authored by Honfika's avatar Honfika

allow to change http/2 body

parent 7330b5c3
...@@ -159,6 +159,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -159,6 +159,9 @@ namespace Titanium.Web.Proxy.Examples.Wpf
//{ //{
//} //}
//if (!e.HttpClient.Request.RequestUri.ToString().Contains("/mail/u/"))
// return;
if (e.HttpClient.Request.HasBody) if (e.HttpClient.Request.HasBody)
{ {
e.HttpClient.Request.KeepBody = true; e.HttpClient.Request.KeepBody = true;
...@@ -177,7 +180,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf ...@@ -177,7 +180,10 @@ namespace Titanium.Web.Proxy.Examples.Wpf
} }
}); });
e.HttpClient.Response.Headers.AddHeader("X-Titanium-Header", "HTTP/2 works"); //e.SetResponseBody(Encoding.ASCII.GetBytes("TITANIUMMMM!!!!"));
//if (!e.HttpClient.Request.RequestUri.ToString().Contains("/mail/u/"))
// return;
//e.HttpClient.Response.Headers.AddHeader("X-Titanium-Header", "HTTP/2 works");
//if (e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Http2) //if (e.HttpClient.ConnectRequest?.TunnelType == TunnelType.Http2)
//{ //{
......
...@@ -91,6 +91,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -91,6 +91,9 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
if (request.HttpVersion == HttpHeader.Version20) if (request.HttpVersion == HttpHeader.Version20)
{ {
// do not send to the remote endpoint
request.Http2IgnoreBodyFrames = true;
request.Http2BodyData = new MemoryStream(); request.Http2BodyData = new MemoryStream();
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
...@@ -100,6 +103,10 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -100,6 +103,10 @@ namespace Titanium.Web.Proxy.EventArguments
request.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true); request.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true);
await tcs.Task; await tcs.Task;
// Now set the flag to true
// So that next time we can deliver body from cache
request.IsBodyRead = true;
} }
else else
{ {
...@@ -157,6 +164,9 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -157,6 +164,9 @@ namespace Titanium.Web.Proxy.EventArguments
{ {
if (response.HttpVersion == HttpHeader.Version20) if (response.HttpVersion == HttpHeader.Version20)
{ {
// do not send to the remote endpoint
response.Http2IgnoreBodyFrames = true;
response.Http2BodyData = new MemoryStream(); response.Http2BodyData = new MemoryStream();
var tcs = new TaskCompletionSource<bool>(); var tcs = new TaskCompletionSource<bool>();
...@@ -166,6 +176,10 @@ namespace Titanium.Web.Proxy.EventArguments ...@@ -166,6 +176,10 @@ namespace Titanium.Web.Proxy.EventArguments
response.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true); response.ReadHttp2BeforeHandlerTaskCompletionSource.SetResult(true);
await tcs.Task; await tcs.Task;
// Now set the flag to true
// So that next time we can deliver body from cache
response.IsBodyRead = true;
} }
else else
{ {
......
...@@ -56,6 +56,15 @@ namespace Titanium.Web.Proxy.Http ...@@ -56,6 +56,15 @@ namespace Titanium.Web.Proxy.Http
internal MemoryStream Http2BodyData; internal MemoryStream Http2BodyData;
internal bool Http2IgnoreBodyFrames;
internal Task Http2BeforeHandlerTask;
/// <summary>
/// Priority used only in HTTP/2
/// </summary>
internal long? Priority;
/// <summary> /// <summary>
/// Keeps the body data after the session is finished. /// Keeps the body data after the session is finished.
/// </summary> /// </summary>
...@@ -201,6 +210,8 @@ namespace Titanium.Web.Proxy.Http ...@@ -201,6 +210,8 @@ namespace Titanium.Web.Proxy.Http
/// </summary> /// </summary>
internal bool Locked { get; set; } internal bool Locked { get; set; }
internal bool BodyAvailable => BodyInternal != null;
internal abstract void EnsureBodyAvailable(bool throwWhenNotReadYet = true); internal abstract void EnsureBodyAvailable(bool throwWhenNotReadYet = true);
/// <summary> /// <summary>
......
This diff is collapsed.
...@@ -125,7 +125,6 @@ namespace Titanium.Web.Proxy ...@@ -125,7 +125,6 @@ namespace Titanium.Web.Proxy
} }
args.TimeLine["Response Sent"] = DateTime.Now; args.TimeLine["Response Sent"] = DateTime.Now;
} }
/// <summary> /// <summary>
......
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