Skip to content

allow read of chunked request in lua #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rzenker
Copy link

@rzenker rzenker commented Apr 10, 2015

No description provided.

@agentzh
Copy link
Member

agentzh commented Apr 10, 2015

@rzenker Thanks for looking into this. Unfortunately this is not sufficient. We need to parse the chunked encoded data ourselves (we could reuse the chunked request body parser in the nginx, but not much else).

@rzenker
Copy link
Author

rzenker commented Apr 11, 2015

@agentzh Does it need to be? Your resty-http chunked body reader already works with it this way. Also, in my case I need the raw encoded body to forward on as unmolested as possible. If it forces parse outside of lua it removes the option for people to use that.

@agentzh
Copy link
Member

agentzh commented Apr 11, 2015

@rzenker Well,

  1. I never wrote any resty-http libraries. You must be referring to some 3rd-party libraries.
  2. I don't think it's really useful to expose the chunked encoding to the Lua land. I think 99% of the time it just just complicates the caller's code.
  3. If you really need raw chunked request bodies, then you should use the raw request cosocket API instead (i.e., ngx.req.socket(true)). See https://github.com/openresty/lua-nginx-module/blob/master/t/116-raw-req-socket.t#L786

@rzenker
Copy link
Author

rzenker commented Apr 11, 2015

@agentzh

Ah, I was confused, but referring to https://github.com/pintsized/lua-resty-http.

I did try to use raw socket first, but then it requires me to handle all the response headers differently then I do with a non-chunked request. If there was a read-only raw that still let the normal nginx responses to be sent that would be great.

I am not understanding the downside to at least allow the body to be read via the non-raw socket right now as opposed to returning the no chunked support error. I could see a case for not wanting to handle the raw chunked body in lua for ease-of-use, but in my case I am just forwarding the request to the backend (mostly unmodified besides new headers). If it returned just the body, my forwarding code would have to support re-chunking the request to the backend.

If I can't convince you of the utility of this option, would you accept a PR that took another argument to ngx.req.socket(false, true) style to either give you the raw body (2nd arg true), or a un-chunk-encoded version (2nd arg false, default)?

@agentzh
Copy link
Member

agentzh commented Apr 12, 2015

@rzenker That lua-resty-http library is written by @pintsized and is a 3rd-party OpenResty library. It was used for upstream HTTP communications, instead of downstream (and we're talking about downstream here).

Will you explain why you want to parse the chunked request bodies yourself instead of letting ngx_lua (or nginx core) taking care of that automatically for you?

Regarding the ngx.req.socket(false, true) proposal, no, it looks ugly to me without outstanding reasons. If you want raw downstream cosockets, then you should want both directions (requests and responses), as in the case of the WebSocket protocol.

@rzenker
Copy link
Author

rzenker commented Apr 13, 2015

@agentzh My use-case is that i'm proxying the request to a backend server in lua. If I can just read the still-chunk encoded response off and then no need to re-chunk-encode it for the backend.

I was pointing out in the https://github.com/pintsized/lua-resty-http/blob/master/lib/resty/http.lua#L286 it already has a compatible reader for chunked if ngx_lua would allow it to be read (as opposed to just refusing). If users need to read a chunked body, but not the chunk encoded version, they could just use that.

If the only option is to force the chunk decoding inside nginx, then a dev needs to create another lua class to re-chunk encode it if they're sending to a backend via lua like in my case.

@agentzh
Copy link
Member

agentzh commented Apr 13, 2015

@rzenker For your use case, you can just assemble the chunked body yourself. That overhead is minimal. I don't see a reason to give you the original chunked data just for that. And ngx_lua still needs to parse the chunked request body somehow if even it does give you the raw chunked data because otherwise it has no ways to determine the end of the request body stream, which MAY cause problems in pipelined or keep-alive requests.

@mergify
Copy link

mergify bot commented Jun 26, 2020

This pull request is now in conflict :(

@mergify
Copy link

mergify bot commented Mar 20, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 20, 2023
@mergify mergify bot removed the conflict label May 10, 2023
@mergify
Copy link

mergify bot commented May 10, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 10, 2023
@mergify mergify bot removed the conflict label Sep 23, 2023
@mergify
Copy link

mergify bot commented Sep 23, 2023

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Sep 23, 2023
@mergify mergify bot removed the conflict label Mar 6, 2024
Copy link

mergify bot commented Mar 6, 2024

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Mar 6, 2024
@mergify mergify bot removed the conflict label May 27, 2024
Copy link

mergify bot commented May 27, 2024

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 27, 2024
@mergify mergify bot removed the conflict label Feb 13, 2025
Copy link

mergify bot commented Feb 13, 2025

This pull request is now in conflict :(

@mergify mergify bot added the conflict label Feb 13, 2025
@mergify mergify bot removed the conflict label May 7, 2025
Copy link

mergify bot commented May 7, 2025

This pull request is now in conflict :(

@mergify mergify bot added the conflict label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants