# Override a set\_empty variable from http params

**URL:** <https://www.ruby-forum.com/t/override-a-set-empty-variable-from-http-params/223695>\
**Category:** NGINX\
**Created:** [October 14, 2012, 8:31pm UTC](https://www.ruby-forum.com/t/override-a-set-empty-variable-from-http-params/223695 "2012-10-14T20:31:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [October 14, 2012, 8:31pm UTC](https://www.ruby-forum.com/t/override-a-set-empty-variable-from-http-params/223695/1 "2012-10-14T20:31:02Z")

</div>

Hi all,

I set the some params to my backend server as shown below

set\_if\_empty $country\_code $http\_x\_country\_code;

proxy\_set\_header X-Country-Code $country\_code;

Now the http\_x\_country\_code comes via the GeoIP module.

Is there a way here I can override this based on an HTTP param I can  
set.

Say [site.com/country=US](http://site.com/country=US) and country variable has greater precedence over  
the http\_x\_country\_code.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 15, 2012, 10:06am UTC](https://www.ruby-forum.com/t/override-a-set-empty-variable-from-http-params/223695/2 "2012-10-15T10:06:06Z")

</div>

On Sun, Oct 14, 2012 at 11:30:22AM -0700, Quintin P. wrote:

> Is there a way here I can override this based on an HTTP param I can set.
> 
> Say [site.com/country=US](http://site.com/country=US) and country variable has greater precedence over  
> the http\_x\_country\_code.

Using “map” you can define:

http {

```
map $arg_country $country_code {
     "" $header_country;
     default $arg_country;
}

map $http_x_country_code $header_country {
     "" $geoip_country_code;
     default $http_x_country_code;
}

...

location / {
    proxy_set_header X-Country-Code $country_code;
    ...

```

–  
Igor S.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![Quintin\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/13edae/32.png) [@Quintin\_P](https://www.ruby-forum.com/u/Quintin_P)\
**Post date:** [October 17, 2012, 6:05am UTC](https://www.ruby-forum.com/t/override-a-set-empty-variable-from-http-params/223695/3 "2012-10-17T06:05:41Z")

</div>

Igor,  
Is this correct?

set $country\_code $arg\_country;  
set\_if\_empty $country\_code $geoip\_country\_code;  
proxy\_set\_header X-Country-Code $country\_code;
