Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Rack streamed proxy causing Net::HTTPOK#read_body called twice
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Fabio Kreusch  
View profile  
 More options Feb 21 2012, 6:23 pm
From: Fabio Kreusch <fabi...@gmail.com>
Date: Tue, 21 Feb 2012 15:23:42 -0800 (PST)
Local: Tues, Feb 21 2012 6:23 pm
Subject: Rack streamed proxy causing Net::HTTPOK#read_body called twice
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Konstantin Haase  
View profile  
 More options Feb 22 2012, 3:41 am
From: Konstantin Haase <k.ha...@finn.de>
Date: Wed, 22 Feb 2012 09:41:11 +0100
Local: Wed, Feb 22 2012 3:41 am
Subject: Re: Rack streamed proxy causing Net::HTTPOK#read_body called twice

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »