Forum: NGINX map a null/missing variable?

Posted by AJ Weber (Guest)
on 2013-03-13 19:22
(Received via mailing list)
OK,

So I'm still working on my caching "issue", but this is a more general
question, so for the sake of indexing and helping others in the future
with (hopefully) a response...

How do I use a map to map the lack of a variable/header/cookie (NULL?)
to a value?  I can't use "default", because when there IS a value it
will be a random set of characters.

So that said, if a regex like ".+" would work for "any value" and I use
'default' for the NULL, I would try that. :)

Thanks in advance,
AJ
Posted by Jonathan Matthews (Guest)
on 2013-03-13 19:27
(Received via mailing list)
On 13 March 2013 18:19, AJ Weber <aweber@comcast.net> wrote:
> So that said, if a regex like ".+" would work for "any value" and I use
> 'default' for the NULL, I would try that. :)

Have you read the docs? http://nginx.org/r/map
Just make sure you have a recent enough version that support regex in
maps, and it /should/ be pretty obvious.

Jonathan
--
Jonathan Matthews // Oxford, London, UK
http://www.jpluscplusm.com/contact.html
Posted by Valentin V. Bartenev (Guest)
on 2013-03-14 01:36
(Received via mailing list)
On Wednesday 13 March 2013 22:19:50 AJ Weber wrote:
> OK,
>
> So I'm still working on my caching "issue", but this is a more general
> question, so for the sake of indexing and helping others in the future
> with (hopefully) a response...
>
> How do I use a map to map the lack of a variable/header/cookie (NULL?)
> to a value?

You can use '' (empty string) value for that.

  wbr, Valentin V. Bartenev

--
http://nginx.org/en/donation.html
Posted by Ruslan Ermilov (Guest)
on 2013-03-14 06:13
(Received via mailing list)
On Wed, Mar 13, 2013 at 02:19:50PM -0400, AJ Weber wrote:
> OK,
>
> So I'm still working on my caching "issue", but this is a more general
> question, so for the sake of indexing and helping others in the future
> with (hopefully) a response...
>
> How do I use a map to map the lack of a variable/header/cookie (NULL?)
> to a value?  I can't use "default", because when there IS a value it
> will be a random set of characters.

You can't handle the lack of a variable (it'll cause a syntax
error in configuration).  Mapping of an unset variable is easy:

map $http_foo $my_var {
    ""      unset;
    default set;
}

> So that said, if a regex like ".+" would work for "any value" and I use
> 'default' for the NULL, I would try that. :)

That's suboptimal.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.