Welcome! Log In Create A New Profile

Advanced

Re: checking headers

Larry Martell
May 31, 2016 09:26AM
On Tue, May 31, 2016 at 7:55 AM, Larry Martell <larry.martell@gmail.com> wrote:
> On Tue, May 31, 2016 at 7:41 AM, Larry Martell <larry.martell@gmail.com> wrote:
>> On Mon, May 30, 2016 at 2:19 PM, Robert Paprocki
>> <rpaprocki@fearnothingproductions.net> wrote:
>>>
>>>
>>> On Sat, May 28, 2016 at 12:48 PM, Larry Martell <larry.martell@gmail.com>
>>> wrote:
>>>>
>>>> Is there any way with nginx to check a request's headers and send back
>>>> a 401 if the headers are not proper?
>>>
>>>
>>>
>>> Yes, you can do with this via the 'map' and 'if' directives. A trivial
>>> example:
>>>
>>> http {
>>> # if the "X-Foo" request header contains the phrase 'data', set $bar
>>> to 1; otherwise, set it to 0
>>> map $http_x_foo $bar {
>>> default 0;
>>> "~data" 1;
>>> }
>>>
>>> server {
>>> location /t {
>>> if ($bar) {
>>> return 401;
>>> }
>>> }
>>> }
>>>
>>> See also http://nginx.org/en/docs/http/ngx_http_map_module.html and
>>> http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#if
>>
>> I added this to the http section:
>>
>> map $http_x_capdata_auth $not_auth {
>> default 1;
>> "authorized" 0;
>> }
>>
>> and this to the location section:
>>
>> if ($not_auth) {
>> return 401;
>> }
>>
>> and it's always returning a 401, even if there is a header:
>>
>> X-Capdata-Auth: authorized
>>
>> And I doing something wrong here? How can I debug this?
>
> Looking with tcpdump I do not see that header field set. The request
> is coming from a django app which is doing a redirect and I set the
> header before the redirect. Guess I have to debug from that side.

I traced the django code all the way through to when the response is
going out and I see this:

(Pdb) response._headers
{'x-capdata-auth': ('X-Capdata-Auth', 'authorized'), 'content-type':
('Content-Type', 'text/html; charset=utf-8'), 'location': ('Location',
'http://foo.bar.com:8000/workitem/12345'), 'vary': ('Vary', 'Cookie')}

Any one have any ideas as to why it doesn't seem to make it over to nginx?

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

checking headers

Larry Martell May 28, 2016 03:50PM

Re: checking headers

Robert Paprocki May 30, 2016 02:20PM

Re: checking headers

Larry Martell May 31, 2016 07:44AM

Re: checking headers

Larry Martell May 31, 2016 07:58AM

Re: checking headers

Larry Martell May 31, 2016 09:26AM

Re: checking headers

Francis Daly May 31, 2016 09:48AM

Re: checking headers

Larry Martell May 31, 2016 10:28AM

Re: checking headers

Francis Daly May 31, 2016 11:40AM

Re: checking headers

Larry Martell May 31, 2016 12:36PM

Re: checking headers

Francis Daly May 31, 2016 04:22PM

Re: checking headers

Larry Martell May 31, 2016 04:50PM

Re: checking headers

Francis Daly May 31, 2016 07:08PM

Re: checking headers

Larry Martell June 01, 2016 04:48PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 265
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready