rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: George <george.ogata@gmail.com>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Re: Middleware and post-request processing
Date: Mon, 6 Jun 2011 10:05:41 -0700 (PDT)	[thread overview]
Message-ID: <df532575-85a7-4568-9daa-5bf9c688f0fb@e21g2000vbz.googlegroups.com> (raw)
In-Reply-To: <2cac8438-1819-4887-bce9-9a99578539db@f31g2000pri.googlegroups.com>

On Jun 3, 7:23 pm, ghazel <gha...@gmail.com> wrote:
> It seems to me that Rack is in need of a new post-response stage of
> processing. This stage would occur after the response is fully written
> and the client is unblocked, and before the next request is processed.
>
> Similar to what OobGC (http://bogomips.org/unicorn.git/tree/lib/unicorn/oob_gc.rb#n59
> ) accomplishes, it is sometimes useful to perform additional
> operations after the response is written without blocking the client.
> For example, the Oink middleware logs statistics about the request,
> but blocks the response since it has no ability not to: (https://github.com/noahd1/oink/blob/4158d71bc9150f011072b2c6eefe73c72...
> ). This processing takes time, and needlessly delays the response.
>
> This proposal would entail something like a single function which is
> called on each middleware after the response is written to the client
> and the socket is closed (depending on the server implementation). For
> servers which have no ability to not block the client or delay further
> requests the function should still be called, and the impact would be
> similar to the behavior today.
>
> Thoughts?

I'm very much in favor of adding such a hook also.

I wrote a gem which does it for a bunch of common web servers:
http://github.com/oggy/rack_after_reply . It adds a list of callback
functions which just get added to the rack environment. I like this
interface in that keeps the callbacks request-local, rather than just
exposing a global hook. Beyond that, I'm totally open to suggestions.

Of course I'd love it if web server authors would provide such a hook
natively, or even maintain the adapter for their server in this gem.

George

  parent reply	other threads:[~2011-06-07  2:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03 23:23 Middleware and post-request processing ghazel
2011-06-04  5:33 ` Eric Wong
2011-06-06 17:05 ` George [this message]
2011-06-07 17:20 ` James Tucker
2012-08-07 10:49   ` ghazel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df532575-85a7-4568-9daa-5bf9c688f0fb@e21g2000vbz.googlegroups.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).