1

I am trying to proxy requests using lua-resty-http module. I am currently passing headers, body, request method, and url for http request which works fine. But when a file upload post request comes it is unable to do so, obviously i haven't configured it to do so. So I want proxy that type of request also. Here is a snap of my so far code, what changes should i make so that it extract file upload data and sends it using lua-resty-http module ->

    local http = require "resty.http"
    local cjson = require "cjson"
    local httpc = http.new()
    local path = ngx.var.request_uri

    local passHeader = {["cookie"]=ngx.req.get_headers()["cookie"]}
    passHeader["content-type"] = ngx.req.get_headers()["content-type"]

    ngx.req.read_body();
    body = ngx.req.get_body_data();
    
    local original_req_uri = "https://"  .. "fakehost.com" .. path
    
    local req_method = ngx.req.get_method()

    local res, err = httpc:request_uri(original_req_uri, {
      method = req_method,
      ssl_verify = false,
      keepalive_timeout = 60000,
      headers = passHeader,
      keepalive_pool = 10,
      body = body
    })

1 Answer 1

0

Read the docs!

https://github.com/openresty/lua-nginx-module#ngxreqget_body_data

POST request may contain big body and nginx may write it to a disk file.

If the request body has been read into disk files, try calling the ngx.req.get_body_file function instead.

PS: IMO approach to proxy HTTP request by Lua is not optimal, because it is the full buffered way. For me it make sense only if we need to issue a subrequest(s). For the main path with most requests processed I recommend to use proxy_pass.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.