lua-resty-http icon indicating copy to clipboard operation
lua-resty-http copied to clipboard

Add support for chunked body to `_send_body`

Open aidvu opened this issue 2 years ago • 0 comments

When trying to send a chunked body, but the function has non-chunked data allow _send_body to properly send chunks w/o modifying the streaming function.

e.g.

local rs, err = ngx.req.socket(true)
local client_body_reader, err = httpc:get_client_body_reader(65535, rs)
local put_res, err = httpc:request_uri(
  response["path"],
  {
    method = "PUT",
    headers = headers,
    body = client_body_reader,
    is_body_function_chunked = true
  }
)

I've also seen the comment:

  • body: The request body as a string, a table of strings, or an iterator function yielding strings until nil when exhausted. Note that you must specify a Content-Length for the request body, or specify Transfer-Encoding: chunked and have your function implement the encoding. See also: get_client_body_reader).

I guess another way would be to wrap the returned body reader in a function and handle it in the wrapper or a parameter for _chunked_body_reader to not unchunk the body, but felt like the library should have support for it.

aidvu avatar Jan 25 '23 17:01 aidvu