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

Support for asynchonous request handling #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ept
Copy link

@ept ept commented Aug 10, 2011

Hi Calvin, thanks for rack-cors, loving it!

We're using asynchonous request processing in our app — you throw :async to tell the web server (e.g. thin) that the response will be sent later; then the web server can serve other requests, and once the response is ready, it is sent out via env['async.callback'].call([status, headers, body]).

I've extended rack-cors to support adding the CORS response headers to asynchonous responses as well. This is done by catching and re-throwing the throw :async, and by wrapping Rack's async callback in a proxy which adds the appropriate headers.

Feel free to use this change if you want :)

Martin

@sujal
Copy link

sujal commented Nov 26, 2011

Hey folks, I've forked cyu's master branch and merged in this request. I then modified it to add support for Goliath (and any other server, I believe, that returns a status of -1 instead of throwing :async. My branch is here: https://github.com/sujal/rack-cors/tree/async_support.

Let me know what you think. I don't have a handy test case for the "throw" case, so if you could make sure I didn't break anything, that would help.

I do need think of a way to write a test for this. Not sure yet how to tackle that.

@funny-falcon
Copy link

Replacing env['async.callback'] should happen before calling original app inside of catch(:async){} cause application could save it to local variable before throwing :async

@karlfreeman
Copy link

Would love to see @sujal's fork make its way into rack-cors. :)

@quezacoatl
Copy link

Why will you not merge this?

@quezacoatl
Copy link

Actually it works to use async-rack instead:

require 'async-rack'

module AsyncRack
  class Cors < AsyncCallback(:Cors)
    include AsyncRack::AsyncCallback::SimpleWrapper
  end
end

@cyu
Copy link
Owner

cyu commented Oct 31, 2013

I haven't had the opportunity to understand async handling in Rack works. I'll try to block off some time to look into this.

@demisx
Copy link

demisx commented Feb 14, 2014

Any update on this please? Will this be merged?

@zabolotnov87
Copy link

👍

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

Successfully merging this pull request may close these issues.

None yet

9 participants