justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.92k stars 598 forks source link

Add new request header has no effect #937

Open ExistentialDysfunction opened 1 year ago

ExistentialDysfunction commented 1 year ago

Hello, I am trying to add an additional header to the request from inside the BeforeRequest event handler, but it has no effect at all.

var explicitEndPoint = new ExplicitProxyEndPoint(System.Net.IPAddress.Any, 18882, true);

            proxyServer.AddEndPoint(explicitEndPoint);
            proxyServer.Start();
            proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
            proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
            proxyServer.BeforeRequest += OnBeforeRequest;
 private static async Task OnBeforeRequest(object sender, SessionEventArgs e) =>
            await Task.Run(() =>
            {
                e.HttpClient.Request.Headers.AddHeader("CustomHeaderName", "CustomHeaderValue");
            });

This is the code, but nothing happens, it has no effect at all.

honfika commented 1 year ago

Why do you need the Task.Run?

Without that it works: image

Upstream proxy is Fiddler: image

Update: Hmm... for me it seems to work with Task.Run, too... could you please create a sample project to reproduce the issue?