local http_req_headers = {}
local http_req_body = nil
local http_res = nil
-- need to bypass all of the request headers
local headers = ngx.req.get_headers(0,true)
for k,v in pairs(headers) do http_req_headers[k] = v end
-- extra proxy headers
http_req_headers["Host"] = req_host
http_req_headers["X-Real-IP"] = ngx.var.remote_addr
local forwarded = http_req_headers["X-Forwarded-For"]
if not forwarded then forwarded = ngx.var.remote_addr
else forwarded = forwarded .. ","..ngx.var.remote_addr
end
http_req_headers["X-Forwarded-For"] = tostring(forwarded)
http_req_headers["Connection"] = ""
http_req_headers["X-Forwarded-Host"] = ngx.var.http_host
local http_req_params = {
version = ngx.req.http_version() or 1.1,
method = ngx.var.request_method,
path = ngx.var.request_uri,
headers = http_req_headers,
body = http_req_body
}
local http_conn = http:new()
http_conn:set_timeout(600000)
local ok,err = http_conn:connect(STREAMSERVER_HOST,STREAMSERVER_PORT)
if ok then
http_req_params["body"] =http_conn:get_client_body_reader()
http_res,err = http_conn:request(http_req_params)
if not http_res then
http_conn:close()
return ngx.exit(500)
end
else
http_conn:close()
return ngx.exit(500)
end
http_conn:proxy_response(http_res)
http_conn:set_keepalive(60000,150)
---------------
yes,i don't specify a chunksize for proxy_response,it's my purpose to keep the same as stream server chunked encoding.