<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>testserver/server.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,5 @@
-
+require 'logger'
+require 'lib/crc32'
 require 'lib/em-proxy' 
 require 'lib/request'  
 require 'lib/proxy_endpoint'
@@ -6,38 +7,56 @@ require 'memcached'
 require 'httparty'                   
 require 'zlib'
 
-$cache = Memcached.new('localhost:11211') 
-
-
-Proxy.start(:host =&gt; &quot;0.0.0.0&quot;, :port =&gt; 3005) do |conn|
-  conn.server :shopify, :host =&gt; &quot;127.0.0.1&quot;,  :port =&gt; 80
+$cache = Memcached.new('localhost:11211')
+$logger = Logger.new(STDOUT)               
 
-  conn.on_data do |data|       
-    
-    request = Request.new(data)   
+class Resolver                    
+  Interesting = /^\/proxy/   
     
-    if request.path =~ /^\/proxy/   
-                                             
+  def self.dispatch(request)                                 
+    if Interesting.match(request.path)                   
+      
       proxy = ProxyEndpoint.new(request.request_uri)
       
       if proxy.available?  
-                      
+        $logger.info &quot;  * Contacting endpoint at #{proxy.endpoint_location}&quot;
+      
         proxy.forward(request)
         
-        cache_key = &quot;proxy-content/#{proxy.content.crc32}&quot;
-                                                             
-        $cache.set cache_key, proxy.content
-                
+        cache_key = &quot;proxy-content/#{crc32(proxy.content)}&quot;
+        
+        $cache.set cache_key, proxy.content       
+        
+        $logger.info &quot;  * Endpoint returned Status:#{proxy.status}, #{proxy.content.length}b content&quot;
+        
         request.add_header('X-Proxy-Content', cache_key)
         request.add_header('X-Proxy-Status', proxy.status)
-        request.data               
-      end
-      
-      request.data
-    else
-      request.data
+      else
+        $logger.info &quot;  * No endpoint found for #{proxy.endpoint_location}&quot;
+      end      
     end
   end
+    
+end
+
+
+Proxy.start(:host =&gt; &quot;0.0.0.0&quot;, :port =&gt; 3005) do |conn|
+  conn.server :shopify, :host =&gt; &quot;127.0.0.1&quot;,  :port =&gt; 2222
+
+  conn.on_data do |data|   
+    
+    request = Request.new(data)    
+
+    $logger.info &quot;*** Request for #{request.request_uri}&quot;
+    
+    Resolver.dispatch(request)    
+    
+    $logger.info &quot;*** Forwarding to backend&quot;
+
+    p request.data
+    request.data
+
+  end
  
   conn.on_response do |backend, resp|
     resp</diff>
      <filename>api_proxy.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,3 @@
-def crc32
-  Zlib.crc32(@body, 0)
+def crc32(content)
+  Zlib.crc32(content, 0)
 end 
-
-def String  
-  def crc32
-    Kernel.crc32(self)
-  end
-end</diff>
      <filename>lib/crc32.rb</filename>
    </modified>
    <modified>
      <diff>@@ -9,12 +9,10 @@ module EventMachine
       end
 
       def connection_completed
-        p [@name, :conn_complete]
         @connected.succeed
       end
 
       def receive_data(data)
-        p [@name, data]
         @data.push data
         @plexer.relay_from_backend(@name, data)
       end
@@ -28,7 +26,6 @@ module EventMachine
       # Notify upstream plexer that the backend server is done
       # processing the request
       def unbind
-        p [@name, :unbind]
         @plexer.unbind_backend(@name)
       end
     end</diff>
      <filename>lib/em-proxy/backend.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,6 @@ module EventMachine
       end
 
       def receive_data(data)
-        p [:connection, data]
         data = @on_data.call(data)
 
         @servers.values.compact.each do |s|
@@ -37,8 +36,6 @@ module EventMachine
       # relay data from backend server to client
       #
       def relay_from_backend(name, data)
-        p [:relay_from_backend, name, data]
-
         data = @on_response.call(name, data)
         send_data data unless data.nil?
       end</diff>
      <filename>lib/em-proxy/connection.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ class ProxyEndpoint
   class TimeoutError &lt; Error; end
   class MethodNotAllowed &lt; Error; end
   
-  ProxyRoot = /https?\:\/\/.*?\/[\w_-]+\/[\w_-]+/
+  ProxyRoot = /https?\:\/\/.*?\/[\w\:_-]+?\/[\w_-]+/
     
   def initialize(uri)
     @uri = uri.to_s                                     
@@ -54,12 +54,6 @@ class ProxyEndpoint
     else                     
       raise MethodNotAllowed.new(api_client)
     end        
-
-    if (200..299).include?(response.code.to_i)
-      response.body
-    else
-      raise RequestError.new(api_client, response)
-    end  
     
     self.content = response.body    
     self.status  = response.code    </diff>
      <filename>lib/proxy_endpoint.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@ class Request
   end             
   
   def request_uri
-    headers['HTTP_REQUEST_URI']
+    'http://' + headers['Host'] + @path
   end                           
   
   def headers</diff>
      <filename>lib/request.rb</filename>
    </modified>
    <modified>
      <diff>@@ -26,6 +26,7 @@ class TestProxyEndpoint &lt; Test::Unit::TestCase
     assert_equal 'http://127.0.0.1/a/b', ProxyEndpoint.new('http://127.0.0.1/a/b').proxy_root
     assert_equal 'http://127.0.0.1/a-b/b_c', ProxyEndpoint.new('http://127.0.0.1/a-b/b_c').proxy_root
     assert_equal 'http://www.proxyserver.com:81/path/to', ProxyEndpoint.new('http://www.proxyserver.com:81/path/to/endpoint?with=param').proxy_root
+    assert_equal 'http://localhost:3005/a/b', ProxyEndpoint.new('http://localhost:3005/a/b').proxy_root
   end
 
   def test_invalid_proxy_root
@@ -59,8 +60,8 @@ class TestProxyEndpoint &lt; Test::Unit::TestCase
     assert_equal 'Third party content', proxy.content
     assert_equal '200', proxy.status
     
-  end  
-  
+  end          
+    
   def test_post_forward                           
     proxy = ProxyEndpoint.new('http://127.0.0.1/a/b')      
     </diff>
      <filename>test/proxy_endpoint_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>4e4ad9e0859783cbd052887d25f2e130d46e5f06</id>
    </parent>
  </parents>
  <author>
    <name>Tobias L&#252;tke</name>
    <email>tobi@jadedpixel.com</email>
  </author>
  <url>http://github.com/tobi/api-proxy/commit/661617ba70ecf0414f9f6de79318a1fdfcff234d</url>
  <id>661617ba70ecf0414f9f6de79318a1fdfcff234d</id>
  <committed-date>2009-05-24T14:51:49-07:00</committed-date>
  <authored-date>2009-05-24T14:51:49-07:00</authored-date>
  <message>Added little sinatra server to test the whole thing</message>
  <tree>5c2655f88dd8a000d3de981648d16a83f4f5c321</tree>
  <committer>
    <name>Tobias L&#252;tke</name>
    <email>tobi@jadedpixel.com</email>
  </committer>
</commit>
