# If bypassServerCache query param is passed as true in request, bypass
# cached responses. See rest_cache
map "$arg_bypassServerCache" $cb_bypassServerCache_in_query_param {
    '1' 1;
    'true' 1;
    default 0;
}

# If nocache query param is passed in request,
# bypass cached resource. See shindig_cache
map "$arg_nocache" $cb_nocache_in_query_param {
    'true' 1;
    '1' 1;
    '' 1;  # Matches empty string (nocache= or nocache)
    default 0;
}

# If bypassServerCache query param is passed as true or nocache query param is passed
# in request, bypass cached resource. See desktop_cache & shindig_cache
map "$http_referer" $cb_bypassServerCache_or_nocache_in_referer_header {
    '~bypassServerCache=true' 1;
    '~nocache=1' 1;
    '~nocache=true' 1;
    '~nocache=0' 0;
    '~nocache=false' 0;
    '~nocache' 1;
    default 0;
}

# If nocache query param is passed or jsp gadget is requested
# during desktop load, bypass cache for shindig ifr
map "$arg_url$arg_nocache" $has_jsp_url_or_no_cache {
    '~*true$' 1;
    '~*1$' 1;
    '~*.jsp.*0$' 1;
    '~*.jsp.*1$' 1;
    '~*.jsp.*true$' 1;
    default 0;
}

map "$cb_bypassServerCache_or_nocache_in_referer_header:$has_jsp_url_or_no_cache" $shindig_cache_bypass {
	"1:0" 1;
	"0:1" 1;
	"1:1" 1;
	default 0;
}

# Extract the port from host header
# If host header is empty then take the server_port value
# If no port found then take the port as 443
map "$http_host" $port_from_request {
    '~:(?<port>.*)$' $port;
    '' $server_port;
    default 443;
}
