Module: Wildcloud::Router::Proxy
- Defined in:
- lib/wildcloud/router/proxy.rb
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #bad_request ⇒ Object
-
#closed? ⇒ Boolean
Tools.
- #initialize(core) ⇒ Object
- #on_body(chunk) ⇒ Object
- #on_headers_complete(headers) ⇒ Object
-
#on_message_begin ⇒ Object
HTTP parser.
- #on_message_complete ⇒ Object
-
#post_init ⇒ Object
EventMachine.
- #receive_data(data) ⇒ Object
- #send_line(data) ⇒ Object
- #unbind ⇒ Object
Instance Attribute Details
#core ⇒ Object (readonly)
Returns the value of attribute core.
24 25 26 |
# File 'lib/wildcloud/router/proxy.rb', line 24 def core @core end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
24 25 26 |
# File 'lib/wildcloud/router/proxy.rb', line 24 def start_time @start_time end |
Instance Method Details
#bad_request ⇒ Object
80 81 82 83 |
# File 'lib/wildcloud/router/proxy.rb', line 80 def bad_request close_connection(true) :stop end |
#closed? ⇒ Boolean
Tools
76 77 78 |
# File 'lib/wildcloud/router/proxy.rb', line 76 def closed? @closed end |
#initialize(core) ⇒ Object
26 27 28 29 |
# File 'lib/wildcloud/router/proxy.rb', line 26 def initialize(core) @core = core @closed = false end |
#on_body(chunk) ⇒ Object
66 67 68 |
# File 'lib/wildcloud/router/proxy.rb', line 66 def on_body(chunk) @client.send_data(chunk) end |
#on_headers_complete(headers) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/wildcloud/router/proxy.rb', line 54 def on_headers_complete(headers) return bad_request unless headers['Host'] target = @core.resolve(headers['Host']) return bad_request unless target if target["socket"] @client = EventMachine.connect(target["socket"], Router::Client, target) else @client = EventMachine.connect(target["address"], target["port"], Router::Client, target) end @client.make_request(self, @parser.http_version.join('.'), @parser.http_method, @parser.request_url, headers) end |
#on_message_begin ⇒ Object
HTTP parser
50 51 52 |
# File 'lib/wildcloud/router/proxy.rb', line 50 def @start_time = Time.now end |
#on_message_complete ⇒ Object
70 71 72 |
# File 'lib/wildcloud/router/proxy.rb', line 70 def @parser = nil end |
#post_init ⇒ Object
EventMachine
33 34 |
# File 'lib/wildcloud/router/proxy.rb', line 33 def post_init end |
#receive_data(data) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/wildcloud/router/proxy.rb', line 36 def receive_data(data) @parser ||= Http::RequestParser.new(self) @parser << data rescue HTTP::Parser::Error => error Router.logger.debug('Proxy') { "Error during parsing #{error.}" } end |
#send_line(data) ⇒ Object
85 86 87 |
# File 'lib/wildcloud/router/proxy.rb', line 85 def send_line(data) send_data("#{data}\r\n") end |
#unbind ⇒ Object
43 44 45 46 |
# File 'lib/wildcloud/router/proxy.rb', line 43 def unbind @closed = true @client.close_connection(true) if @client and !@client.closed? end |