rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Fabio Kreusch <fabiokr@gmail.com>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Rack streamed proxy causing Net::HTTPOK#read_body called twice
Date: Tue, 21 Feb 2012 15:23:42 -0800 (PST)	[thread overview]
Message-ID: <e66075e3-a96f-4e2c-ac1e-793f30ea9dbe@p13g2000yqd.googlegroups.com> (raw)

So, I have a Rack application which acts as a proxy. I have
implemented a net/http api to deal with the communication, so the rack
app basically calls it like this:

api.new(request_method, rack_request, options).response
.response returns a valid rack response [status, headers, body].

Body is an instance of the api, and it its implementation is like this
(simplified version):

def initialize
  ...
  @proxy_connection = Net::HTTP.start(proxied_uri.host,
proxied_uri.port)
  @proxy_connection.request(@proxy_request) do |response|
    @proxy_response = response
  end
end

def each(&block)
  @proxy_response.read_body(&block)
end

def to_s
  @proxy_response.read_body
end
The rack app can then call the proxied service with a full response
with to_s, or as a streaming and receive the response in chunks with
each.

The thing is, when I return the response in rack, I'm getting the
following stack trace: https://gist.github.com/1879724

Apparently, the server or rack is calling 'each' more than once, but
I'm not sure what might be causing it.

The Rack app is running under rails 3.2.1.

             reply	other threads:[~2012-02-22  4:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-21 23:23 Fabio Kreusch [this message]
2012-02-22  8:41 ` Rack streamed proxy causing Net::HTTPOK#read_body called twice Konstantin Haase

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=e66075e3-a96f-4e2c-ac1e-793f30ea9dbe@p13g2000yqd.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).