1bf215546Sopenharmony_ciset $proxy_authorization ''; 2bf215546Sopenharmony_ci 3bf215546Sopenharmony_ciset_by_lua $proxyuri ' 4bf215546Sopenharmony_ci unescaped = ngx.unescape_uri(ngx.var.arg_uri); 5bf215546Sopenharmony_ci it, err = ngx.re.match(unescaped, "(https?://)(.*@)?([^/]*)(/.*)?"); 6bf215546Sopenharmony_ci if not it then 7bf215546Sopenharmony_ci -- Hack to cause nginx to return 404 8bf215546Sopenharmony_ci return "http://localhost/404" 9bf215546Sopenharmony_ci end 10bf215546Sopenharmony_ci 11bf215546Sopenharmony_ci scheme = it[1]; 12bf215546Sopenharmony_ci authstring = it[2]; 13bf215546Sopenharmony_ci host = it[3]; 14bf215546Sopenharmony_ci query = it[4]; 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_ci if ngx.var.http_authorization and ngx.var.http_authorization ~= "" then 17bf215546Sopenharmony_ci ngx.var.proxy_authorization = ngx.var.http_authorization; 18bf215546Sopenharmony_ci elseif authstring then 19bf215546Sopenharmony_ci auth = string.sub(authstring, 0, -2); 20bf215546Sopenharmony_ci auth64 = ngx.encode_base64(auth); 21bf215546Sopenharmony_ci ngx.var.proxy_authorization = "Basic " .. auth64; 22bf215546Sopenharmony_ci end 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci -- Default to / if none is set to avoid using the request_uri query 25bf215546Sopenharmony_ci if not query then 26bf215546Sopenharmony_ci query = "/"; 27bf215546Sopenharmony_ci end 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci return scheme .. host .. query; 30bf215546Sopenharmony_ci'; 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ciadd_header X-GG-Cache-Status $upstream_cache_status; 33bf215546Sopenharmony_ciproxy_set_header Authorization $proxy_authorization; 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ciproxy_pass $proxyuri; 36bf215546Sopenharmony_ci# Redirect back to ourselves on 301 replies 37bf215546Sopenharmony_ciproxy_redirect ~^(.*)$ /cache/?uri=$1; 38