Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core + Nginx losing HTTP Header

I'm sending HTTP GET Request to my API with custom Header

var request = new RestRequest(endpoint, Method.GET);
request.AddHeader("__Test", data);
var response = client.Execute(request);

Everything works fine on localhost, but when I deploy API on server which is using Nginx then this header is "lost"

That's my nginx config

location / {
    proxy_pass         http://localhost:5000;
    proxy_http_version 1.1;
    proxy_set_header   Upgrade $http_upgrade;
    proxy_set_header   Connection keep-alive;
    proxy_set_header   Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
}

Startup.cs

app.UseForwardedHeaders(new ForwardedHeadersOptions
{
    ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});

app.UseHttpsRedirection();

This works fine on localhost, but not on server:

HttpContext.Request.Headers.TryGetValue("__Test", out var data)

Anybody has an idea what can go wrong?

like image 998
tezzly Avatar asked Nov 19 '25 14:11

tezzly


1 Answers

Problem occured because I used __ in header's name

Solution:

Use

underscores_in_headers on;

in

nginx.conf

like image 106
tezzly Avatar answered Nov 21 '25 03:11

tezzly