Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom headers, but not seeing them in Fiddler #1477

Closed
sarchibald-mdsol opened this issue Dec 22, 2021 · 13 comments
Closed

Adding custom headers, but not seeing them in Fiddler #1477

sarchibald-mdsol opened this issue Dec 22, 2021 · 13 comments
Labels
Type: Bug Something isn't working

Comments

@sarchibald-mdsol
Copy link

sarchibald-mdsol commented Dec 22, 2021

Describe the bug

I'm trying to add some headers to all my routes using the code below. But when I look at my requests in Fiddler, I don't see any of my headers added to the final request.

To Reproduce

Here is the current code:

public void ConfigureServices(IServiceCollection services)
{
	// Add the reverse proxy to capability to the server
	services.AddReverseProxy()
		.LoadFromConfig(Configuration.GetSection("ReverseProxy"))
		.AddTransforms(builderContext =>
		{
			builderContext.AddPathPrefix(@"/");
			builderContext.AddRequestTransform(async transformContext =>
			{
				transformContext.ProxyRequest.Headers.Add("Authorization", "Basic <hidden-obfuscated>");
				transformContext.ProxyRequest.Headers.Add("Custom-Token", "doodah");
			});
		});

	//services.AddHttpForwarder();
	services.AddCors(options =>
		options.AddPolicy(
			"openPolicy",
			policy =>
				policy
					.AllowAnyOrigin()
					.AllowAnyMethod()
					.AllowAnyHeader()
		)
	);
}

Got Exceptions? Include both the message and the stack trace

Further technical details

YARP 1.0.0
.NET5
React front end
Windows

Here's a snapshot of what's in Fiddler after executing a request:
2021-12-22 07_44_47-Window

@sarchibald-mdsol sarchibald-mdsol added the Type: Bug Something isn't working label Dec 22, 2021
@MihaZupan
Copy link
Member

using the code below

Can you please share the code you are using?

@sarchibald-mdsol
Copy link
Author

sarchibald-mdsol commented Dec 22, 2021 via email

@Tratcher
Copy link
Member

Fiddler only shows you the requests from the client to the proxy by default, it doesn't intercept requests from the proxy to the destination without additional config.

Can you share your appsettings.json file as well, it's hard to tell which parts of this flow belong to the proxy.

What are you expecting this to do? builderContext.AddPathPrefix(@"/"); You wouldn't normally add just a slash to the request path.

@sarchibald-mdsol
Copy link
Author

sarchibald-mdsol commented Dec 22, 2021 via email

@Tratcher
Copy link
Member

Tratcher commented Dec 22, 2021

I used pathprefix of “/” because the documentation for the config version implied a pathprefix was required, and I want all the routes that come into the proxy server to have these headers added. I initially tried without the pathprefix in the code version, but the results are always the same.

Match:Path is required in the route config, AddPathPrefix does something else and is not required, remove it.

It looks like you're being redirected (302) from localhost to modsreporting-dev.mdsol.com, so that second request is bypassing the proxy entirely. Some sites do this defensively if the host header doesn't match. You can check/share the info level logs from the proxy to confirm. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-6.0#configure-logging

@sarchibald-mdsol
Copy link
Author

sarchibald-mdsol commented Dec 22, 2021 via email

@sarchibald-mdsol
Copy link
Author

sarchibald-mdsol commented Dec 22, 2021 via email

@Tratcher
Copy link
Member

Your appsettings.json looks fine then. Check the logs from YARP to see what it says about those requests.

@samsp-msft
Copy link
Contributor

@sarchibald-mdsol - following up after the US holidays - did you resolve your issue?

@karelz
Copy link
Member

karelz commented Jan 18, 2022

Triage: No response for 2+ weeks, closing. Feel free to reopen if there is more info available. Thanks!

@karelz karelz closed this as completed Jan 18, 2022
@SEnglishSMP
Copy link

Fiddler only shows you the requests from the client to the proxy by default, it doesn't intercept requests from the proxy to the destination without additional config.

@Tratcher Would you please point me to some documentation on what that additional config is?

@Tratcher
Copy link
Member

Tratcher commented Dec 8, 2022

Fiddler injects itself as an outbound client proxy. YARP disables outbound client proxy support on HttpClient by default for performance reasons, it expects to be able to directly access destinations. You'd have to turn that back on.

https://microsoft.github.io/reverse-proxy/articles/http-client-config.html#configuring-the-http-client
https://microsoft.github.io/reverse-proxy/articles/http-client-config.html#custom-iforwarderhttpclientfactory

@SEnglishSMP
Copy link

@Tratcher, thanks. That got pointed in the right direction.

For anyone else looking to enable Fiddler debugging with YARP, I had to add the following when configuring services:

services
    .AddReverseProxy()
    .ConfigureHttpClient((context, handler) =>
    {
        handler.UseProxy = true;
        handler.Proxy = WebRequest.DefaultWebProxy;
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants