rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* Rack streamed proxy causing Net::HTTPOK#read_body called twice
@ 2012-02-21 23:23 Fabio Kreusch
  2012-02-22  8:41 ` Konstantin Haase
  0 siblings, 1 reply; 2+ messages in thread
From: Fabio Kreusch @ 2012-02-21 23:23 UTC (permalink / raw)
  To: Rack Development

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Rack streamed proxy causing Net::HTTPOK#read_body called twice
  2012-02-21 23:23 Rack streamed proxy causing Net::HTTPOK#read_body called twice Fabio Kreusch
@ 2012-02-22  8:41 ` Konstantin Haase
  0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Haase @ 2012-02-22  8:41 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 1448 bytes --]

Unfortunately, the Rack specification does not make any assumptions on whether each will be called once or twice or how to reflect upon that. So you always have to assume that each might be called more than once.

Konstantin 

On Wednesday, February 22, 2012 at 12:23 AM, Fabio Kreusch wrote:

> 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. 


[-- Attachment #2: Type: text/html, Size: 2406 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-02-22  8:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21 23:23 Rack streamed proxy causing Net::HTTPOK#read_body called twice Fabio Kreusch
2012-02-22  8:41 ` Konstantin Haase

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).