| 1 |
set $proxy_authorization ''; |
| 2 |
|
| 3 |
set_by_lua $proxyuri ' |
| 4 |
local unescaped = ngx.unescape_uri(ngx.var.arg_uri); |
| 5 |
local it, err = ngx.re.match(unescaped, "(https?://)(.*@)?([^/]*)(/.*)?"); |
| 6 |
if not it then |
| 7 |
-- Hack to cause nginx to return 404 |
| 8 |
return "http://localhost/404" |
| 9 |
end |
| 10 |
|
| 11 |
local scheme = it[1]; |
| 12 |
local authstring = it[2]; |
| 13 |
local host = it[3]; |
| 14 |
local query = it[4]; |
| 15 |
|
| 16 |
if ngx.var.http_authorization and ngx.var.http_authorization ~= "" then |
| 17 |
ngx.var.proxy_authorization = ngx.var.http_authorization; |
| 18 |
elseif authstring then |
| 19 |
auth = string.sub(authstring, 0, -2); |
| 20 |
auth64 = ngx.encode_base64(auth); |
| 21 |
ngx.var.proxy_authorization = "Basic " .. auth64; |
| 22 |
end |
| 23 |
|
| 24 |
-- Default to / if none is set to avoid using the request_uri query |
| 25 |
if not query then |
| 26 |
query = "/"; |
| 27 |
end |
| 28 |
|
| 29 |
return scheme .. host .. query; |
| 30 |
'; |
| 31 |
|
| 32 |
# Rewrite the location header to redirect back to this server. Do |
| 33 |
# this using lua header filtering to allow for url encoding the original |
| 34 |
# location header for use as a query parameter. |
| 35 |
header_filter_by_lua_block { |
| 36 |
if ngx.header.location then |
| 37 |
ngx.header.location = "/cache?uri=" .. ngx.escape_uri(ngx.header.location); |
| 38 |
end |
| 39 |
} |
| 40 |
|
| 41 |
add_header X-GG-Cache-Status $upstream_cache_status; |
| 42 |
proxy_set_header Authorization $proxy_authorization; |
| 43 |
|
| 44 |
proxy_pass $proxyuri; |