Note that there are some explanatory texts on larger screens.

plurals
  1. POEventMachine Proxy -- HTTP Proxy mixing up request/response pairs
    primarykey
    data
    text
    <p>I have the following code (just as a test) and I want to create an HTTP proxy using EventMachine. The code below is an example on the es-proxy GitHub page. However, when I run this and open up a website that has a moderate amount of images, the images start loading incorrectly. What I mean by this is that some images are loaded twice or if I request my icon for the navigation bar, I instead get the profile picture. This is especially evident if I refresh the page a few times. </p> <p>It seems that the responses do not correspond to the matching request; causing everything to be jumbled. However, I'm not sure why this is. The code below seems simple enough for this to not be a problem. </p> <pre><code>require 'rubygems' require 'em-proxy' require 'http/parser' # gem install http_parser.rb require 'uuid' # gem install uuid # &gt; ruby em-proxy-http.rb # &gt; curl --proxy localhost:9889 www.google.com host = "0.0.0.0" port = 9889 puts "listening on #{host}:#{port}..." Proxy.start(:host =&gt; host, :port =&gt; port) do |conn| @p = Http::Parser.new @p.on_headers_complete = proc do |h| session = UUID.generate puts "New session: #{session} (#{h.inspect})" host, port = h['Host'].split(':') conn.server session, :host =&gt; host, :port =&gt; (port || 80) conn.relay_to_servers @buffer @buffer = '' end @buffer = '' conn.on_connect do |data,b| puts [:on_connect, data, b].inspect end conn.on_data do |data| @buffer &lt;&lt; data @p &lt;&lt; data data end conn.on_response do |backend, resp| #puts [:on_response, backend, resp].inspect resp end conn.on_finish do |backend, name| puts [:on_finish, name].inspect end end </code></pre> <p><strong>Update</strong></p> <p>I believe I have insight as to what is happening but, still no way of solving my problem. I am creating a server for each request and when I relay my requests I have multiple servers. Then in the on response I should only be returning the response if it is from the correct server. However, I don't have a way to correlate this as of yet. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload