Class: ReverseTunnel::Client::ApiServer
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- ReverseTunnel::Client::ApiServer
- Includes:
- EM::HttpServer
- Defined in:
- lib/reverse-tunnel/client.rb
Instance Attribute Summary collapse
-
#tunnel ⇒ Object
Returns the value of attribute tunnel.
Instance Method Summary collapse
-
#initialize(tunnel) ⇒ ApiServer
constructor
A new instance of ApiServer.
- #post_init ⇒ Object
- #process_http_request ⇒ Object
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
#tunnel ⇒ Object
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_init ⇒ Object
13 14 15 16 |
# File 'lib/reverse-tunnel/client.rb', line 13 def post_init super no_environment_strings end |
#process_http_request ⇒ Object
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 |