Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 64 lines (43 sloc) 1.607 kB
661617b @tobi Added little sinatra server to test the whole thing
authored
1 require 'logger'
2 require 'lib/crc32'
3d38548 @tobi Separated the differnet parts of the app into their own files. Accord…
authored
3 require 'lib/em-proxy'
4 require 'lib/request'
5 require 'lib/proxy_endpoint'
e9998ed @tobi First checkin
authored
6 require 'memcached'
7 require 'httparty'
8 require 'zlib'
9
661617b @tobi Added little sinatra server to test the whole thing
authored
10 $cache = Memcached.new('localhost:11211')
11 $logger = Logger.new(STDOUT)
e9998ed @tobi First checkin
authored
12
661617b @tobi Added little sinatra server to test the whole thing
authored
13 class Resolver
14 Interesting = /^\/proxy/
3d38548 @tobi Separated the differnet parts of the app into their own files. Accord…
authored
15
661617b @tobi Added little sinatra server to test the whole thing
authored
16 def self.dispatch(request)
17 if Interesting.match(request.path)
18
3d38548 @tobi Separated the differnet parts of the app into their own files. Accord…
authored
19 proxy = ProxyEndpoint.new(request.request_uri)
e9998ed @tobi First checkin
authored
20
21 if proxy.available?
661617b @tobi Added little sinatra server to test the whole thing
authored
22 $logger.info " * Contacting endpoint at #{proxy.endpoint_location}"
23
3d38548 @tobi Separated the differnet parts of the app into their own files. Accord…
authored
24 proxy.forward(request)
25
661617b @tobi Added little sinatra server to test the whole thing
authored
26 cache_key = "proxy-content/#{crc32(proxy.content)}"
27
28 $cache.set cache_key, proxy.content
29
30 $logger.info " * Endpoint returned Status:#{proxy.status}, #{proxy.content.length}b content"
31
3d38548 @tobi Separated the differnet parts of the app into their own files. Accord…
authored
32 request.add_header('X-Proxy-Content', cache_key)
e9998ed @tobi First checkin
authored
33 request.add_header('X-Proxy-Status', proxy.status)
661617b @tobi Added little sinatra server to test the whole thing
authored
34 else
35 $logger.info " * No endpoint found for #{proxy.endpoint_location}"
36 end
e9998ed @tobi First checkin
authored
37 end
38 end
661617b @tobi Added little sinatra server to test the whole thing
authored
39
40 end
41
42
43 Proxy.start(:host => "0.0.0.0", :port => 3005) do |conn|
44 conn.server :shopify, :host => "127.0.0.1", :port => 2222
45
46 conn.on_data do |data|
47
48 request = Request.new(data)
49
50 $logger.info "*** Request for #{request.request_uri}"
51
52 Resolver.dispatch(request)
53
54 $logger.info "*** Forwarding to backend"
55
56 p request.data
57 request.data
58
59 end
e9998ed @tobi First checkin
authored
60
61 conn.on_response do |backend, resp|
62 resp
63 end
64 end
Something went wrong with that request. Please try again.