8000 After/between request callback · Issue #1060 · rack/rack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

After/between request callback #1060

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

Closed
maxnordlund opened this issue Apr 24, 2016 · 3 comments
Closed

After/between request callback #1060

maxnordlund opened this issue Apr 24, 2016 · 3 comments

Comments

@maxnordlund
Copy link
maxnordlund commented Apr 24, 2016

Hi, I couldn't find an issue with this so here it goes.

I would like to run some code after the request has been flushed to the client but before the next request. Essentially be able to queue up some work per request without affecting the load time. An example is to defer some logging/profiling, or send an email.

Is this possible to do this already? Or is it possible to add? Thoughts and feedback more then welcome.

@janko
Copy link
Contributor
janko commented Apr 12, 2017

@maxnordlund I think Rack::BodyProxy is what you're looking for. You can wrap your response body that you would return in a Rack::BodyProxy object, pass it a block to be called when response body is closed, and return the Rack::BodyProxy object as your response body.

Rack::BodyProxy.new(body) do
  # will be executed after response body has been written to the client
end

@maxnordlund
Copy link
Author

Cool, sadly I'm not coding any Ruby/Rails at the moment. But I hope this helps whoever comes by next.

@jeremy
Copy link
Member
jeremy commented Mar 19, 2020

Puma supports this via env["rack.after_reply"] << -> { do_stuff }. This is run even if the response body is not closed, such as when an exception is raised in a middleware.

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

3 participants
0