I am adding application specific headers in my GET request. I am able to view the header in my Chrome's developer console. So it seems they are being sent to the server.
The header is chart_type
But, when I try to access the headers in my flask application it, is missing from request.headers
The output of request.headers is below:
X-Forwarded-For: 127.0.0.1
Host: localhost
X-Nginx-Proxy: true
Connection: close
Pragma: no-cache
Cache-Control: no-cache
Sec-Ch-Ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
Sec-Ch-Ua-Mobile: ?0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Sec-Ch-Ua-Platform: "macOS"
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:8080/stock-market-pattern-modelling/quote?symbol=AAPL
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
I am adding application specific headers in my GET request. I am able to view the header in my Chrome's developer console. So it seems they are being sent to the server.
The header is chart_type
But, when I try to access the headers in my flask application it, is missing from request.headers
The output of request.headers is below:
X-Forwarded-For: 127.0.0.1
Host: localhost
X-Nginx-Proxy: true
Connection: close
Pragma: no-cache
Cache-Control: no-cache
Sec-Ch-Ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"
Sec-Ch-Ua-Mobile: ?0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Sec-Ch-Ua-Platform: "macOS"
Accept: */*
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:8080/stock-market-pattern-modelling/quote?symbol=AAPL
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Share
Improve this question
asked Dec 14, 2022 at 9:10
PawanPawan
1794 silver badges19 bronze badges
4
- 1 Does it work when you use something like postman to call your endpoint with a custom header? Also, what code do you use to fetch the headers? Is your request rerouted before it ends up in Flask? – JustLudo Commented Dec 14, 2022 at 9:22
- Good Point. I am using NGINX reverse proxy. I will check into it right now – Pawan Commented Dec 14, 2022 at 9:35
- Can you help me with this question stackoverflow./questions/74798000/… – Pawan Commented Dec 14, 2022 at 12:03
- It seems @codeape already answered this question. It was indeed the underscores in the headernames. Learnt something new today. – JustLudo Commented Dec 14, 2022 at 15:55
1 Answer
Reset to default 10While underscores are allowed in header names, some server implementations silently drop headers with underscores in the name.
For instance Nginx with the default configuration will ignore headers with underscore in the name (see underscores_in_headers
and ignore_invalid_headers
documentation).
I therefore suggest that you try the header name Chart-Type
instead of chart_type
.