Skip to content
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

Example of big file proxy #23

Open
misiek08 opened this issue Feb 13, 2014 · 6 comments
Open

Example of big file proxy #23

misiek08 opened this issue Feb 13, 2014 · 6 comments

Comments

@misiek08
Copy link

I'm using lua with nginx and I need to do some piping. I need to auth in lua on 3rd party website and then download file but not to my server, but directly piping to user.

nginx ==> 3rdparty/auth
nginx <== 3rdparty: You are logged in
nginx ==> 3rdparty/get/file/x.tar.gz;
nginx <== 3rdparty: Here you are... binary data
nginx.on_3rdparty_chunk(data) ==> nginx.send_to_client(data)

Is it possible? Can you give a simple example?

@agentzh
Copy link
Collaborator

agentzh commented Feb 13, 2014

@misiek08 I'm not the maintainer of liseen's lua-resty-http you're posting the issue to but I know James Hurst's version of lua-resty-http does support reading big response bodies in chunks from the remote end:

https://github.com/pintsized/lua-resty-http

To implement strict non-buffered proxying, you need to read a chunk from the upstream and then call

ngx.print(data_chunk)
ngx.flush(true)

afterwards. That is, sending out a data chunk to the downstream completely before reading the next data chunk from the upstream.

@misiek08
Copy link
Author

I think that's right time to all lua-resty-http's get together, make one powerful and rich-feature library :)

One library accepts cookie as array (it's very important for me), one have raw api to use chunk instead of whole body (it's most important feature) and other have some different thing...

@agentzh thank's for that reply, I just thought that I can't do this that way. I wasn't trying, because I'll have time at the weekend for it.

@agentzh
Copy link
Collaborator

agentzh commented Feb 13, 2014

@misiek08 Yeah, hopefully there will be an official lua-resty-http library soon :)

@misiek08
Copy link
Author

I'm looking for ability to set cookie file (like in curl) or multiple cookies as array... I'm now working on code.

@misiek08
Copy link
Author

for key, values in pairs(headers) do
        if type(values) ~= "table" then
            values = {values}
        end

        key = tostring(key)
        for _, value in pairs(values) do
            req[c] = key .. ": " .. tostring(value) .. "\r\n"
            c = c + 1
        end
    end

Here we need change for cookies :)

@agentzh
Copy link
Collaborator

agentzh commented Feb 13, 2014

@misiek08 I think you can just construct the Cookie headers yourself. But I'm no expert of this particular Lua library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants