Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Add new request header has no effect #937

Open
ExistentialDysfunction opened this issue Nov 14, 2022 · 1 comment
Open

Add new request header has no effect #937

ExistentialDysfunction opened this issue Nov 14, 2022 · 1 comment

Comments

@ExistentialDysfunction
Copy link

ExistentialDysfunction commented Nov 14, 2022

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.

@ExistentialDysfunction ExistentialDysfunction changed the title Add new request header Add new request header has no effect Nov 14, 2022
@honfika
Copy link
Collaborator

honfika commented Dec 25, 2022

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants