Class: ReverseTunnel::Client::ApiServer

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::HttpServer
Defined in:
lib/reverse-tunnel/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tunnel) ⇒ ApiServer

Returns a new instance of ApiServer.



9
10
11
# File 'lib/reverse-tunnel/client.rb', line 9

def initialize(tunnel)
  @tunnel = tunnel
end

Instance Attribute Details

#tunnelObject

Returns the value of attribute tunnel.



7
8
9
# File 'lib/reverse-tunnel/client.rb', line 7

def tunnel
  @tunnel
end

Instance Method Details

#post_initObject



13
14
15
16
# File 'lib/reverse-tunnel/client.rb', line 13

def post_init
  super
  no_environment_strings
end

#process_http_requestObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/reverse-tunnel/client.rb', line 18

def process_http_request
  ReverseTunnel.logger.debug { "Process http request #{@http_request_uri}" }

  response = EM::DelegatedHttpResponse.new(self)
  response.status = 200
  response.content_type 'application/json'

  begin
    if @http_request_uri =~ %r{^/status(.json)?$} and @http_request_method == "GET"
      response.content = tunnel.to_json
    end
  rescue => e
    ReverseTunnel.logger.error "Error in http request processing: #{e}"
    response.status = 500
  end

  if response.content.nil?
    response.status = 404
  end

  response.send_response
end