Module: QueueingProxy::Worker::Upstream::Client

Defined in:
lib/queueing_proxy/worker.rb

Overview

The connection handler for EM.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#upstreamObject

Returns the value of attribute upstream.



70
71
72
# File 'lib/queueing_proxy/worker.rb', line 70

def upstream
  @upstream
end

Instance Method Details

#connection_completedObject

Succesful connection!



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/queueing_proxy/worker.rb', line 73

def connection_completed
  # Setup our callback for when the upstream response hits us
  upstream.response.on_headers_complete = Proc.new {
    upstream.succeed
    close_connection
    :stop
  }

  # Send the HTTP request upstream
  send_data upstream.payload
end

#receive_data(data) ⇒ Object

Read the response of the upstream proxy



86
87
88
89
90
91
92
93
# File 'lib/queueing_proxy/worker.rb', line 86

def receive_data(data)
  begin
    upstream.response << data
  rescue HTTP::Parser::Error
    upstream.fail
    close_connection
  end
end

#unbindObject

If something bad happens to the connection, bind gets called



96
97
98
# File 'lib/queueing_proxy/worker.rb', line 96

def unbind
  upstream.fail
end