Class: Api2cart::Daemon::ProxyConnectionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/api2cart/daemon/proxy_connection_handler.rb

Instance Method Summary collapse

Instance Method Details

#handle_proxy_connection(client_socket) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/api2cart/daemon/proxy_connection_handler.rb', line 5

def handle_proxy_connection(client_socket)
  client_socket = Reel::Spy.new client_socket

  http_message = read_http_message(client_socket)

  response = if not_proxy_request?(http_message)
               bad_request
             else
               begin
                 processed_message = process_client_request(http_message)
                 send_request_to_remote_server(http_message.request_host, http_message.request_port, processed_message)
               rescue Exception => e
                 puts "! Problem connecting to server: #{e.inspect}"
                 internal_server_error(e)
               end
             end

  send_response_to_client(client_socket, response)
end