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

Already on GitHub? Sign in to your account

X-Sendfile/X-Accel-Redirect support #106

Closed
johnae opened this Issue Sep 9, 2011 · 3 comments

Comments

Projects
None yet
4 participants

johnae commented Sep 9, 2011

I've been trying to implement something like this but I'm still a newbie when it comes to node and node-http-proxy. Basically, what I'd like to see in node-http-proxy is support for a more nginx-like x-accel-redirect. Nginx can not only send files from the local disk but also send them from another backend server. So you could in, say Rails, do:

headers['X-Accel-Redirect'] = '/some/file.mp4'
or even
headers['X-Accel-Redirect'] = 'http://myotherbackend.example.com:1234/some/file.mp4'

I guess node-http-proxy would have to support checking the headers returned from backend and if it contains X-Accel-Redirect (or perhaps X-Sendfile - or even something else) it would send that out instead. Something like that.

At first I thought perhaps a middleware could accomplish this but well, I'm a newbie, and couldn't figure out how. Then I cloned the source and started hacking on it... haven't got very far yet though.

We need this since we'd like to offload this stuff from Rails onto the frontends. We currently use nginx as our frontend but nginx has problems with http 1.1 to backends and we must absolutely have 1.1 to our backends(these are not rails backends). We also use node which we'd actually like to use as our frontend going forward.

Contributor

dominictarr commented Sep 9, 2011

you could do this with middlewares, but the trick is that since the middleware system was copied from connect it delt mainly with modifying the request. what you are talking about here is modifying the response.

you proxy to your server (rails) which writes the X-Accel-Redirect header, then responds to the proxy, the proxy reads the header, sees x-accel-redirect and makes another request, to the redirect url.

currently, middlewares that modify the response work by monkeypatching the response object, have a look at https://github.com/nateps/connect-gzip

you would intercept the calls to write and end like here: https://github.com/nateps/connect-gzip/blob/master/lib/gzip.js#L40-49 but instead of piping it through the gzip command, you would make a whole new request.

we currently don't have a middleware system for responses...

you won't be a newbie once you have this licked. welcome to the bleeding edge.

Owner

indexzero commented Mar 9, 2013

This is blocked by nodejs core since it does not have sendfile.

Owner

jcrugzz commented Oct 30, 2015

Closing, node core still does not have sendFile

@jcrugzz jcrugzz closed this Oct 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment