Class: Meshchat::Network::Local::Server
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- Meshchat::Network::Local::Server
- Includes:
- EM::HttpServer
- Defined in:
- lib/meshchat/network/local/server.rb
Overview
This is created every request
Constant Summary collapse
- OK =
200
- BAD_REQUEST =
400
- NOT_AUTHORIZED =
401
- FORBIDDEN =
403
- SERVER_ERROR =
500
Instance Attribute Summary collapse
-
#_message_dispatcher ⇒ Object
readonly
Returns the value of attribute _message_dispatcher.
-
#_request_processor ⇒ Object
readonly
Returns the value of attribute _request_processor.
Instance Method Summary collapse
- #build_response(s = OK, message = '') ⇒ Object
-
#initialize(message_dispatcher) ⇒ Server
constructor
A new instance of Server.
- #process(raw) ⇒ Object
- #process_http_request ⇒ Object
Constructor Details
#initialize(message_dispatcher) ⇒ Server
Returns a new instance of Server.
18 19 20 21 22 23 24 |
# File 'lib/meshchat/network/local/server.rb', line 18 def initialize() @_message_dispatcher = @_request_processor = Incoming::RequestProcessor.new( network: NETWORK_LOCAL, message_dispatcher: ) end |
Instance Attribute Details
#_message_dispatcher ⇒ Object (readonly)
Returns the value of attribute _message_dispatcher.
10 11 12 |
# File 'lib/meshchat/network/local/server.rb', line 10 def @_message_dispatcher end |
#_request_processor ⇒ Object (readonly)
Returns the value of attribute _request_processor.
10 11 12 |
# File 'lib/meshchat/network/local/server.rb', line 10 def _request_processor @_request_processor end |
Instance Method Details
#build_response(s = OK, message = '') ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/meshchat/network/local/server.rb', line 60 def build_response(s = OK, = '') response = EM::DelegatedHttpResponse.new(self) response.status = s response.content_type 'text/json' response.content = response.send_response end |
#process(raw) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/meshchat/network/local/server.rb', line 45 def process(raw) # decode, etc _request_processor.process(raw) rescue Errors::NotAuthorized build_response NOT_AUTHORIZED rescue Errors::Forbidden build_response FORBIDDEN rescue Errors::BadRequest build_response BAD_REQUEST rescue => e Display.error e. Display.error e.backtrace.join("\n") build_response SERVER_ERROR, e. end |
#process_http_request ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/meshchat/network/local/server.rb', line 26 def process_http_request # the http request details are available via the following instance variables: # @http_protocol # @http_request_method # @http_cookie # @http_if_none_match # @http_content_type # @http_path_info # @http_request_uri # @http_query_string # @http_post_content # @http_headers # view what instance variables are available thorugh the # instance_variables method process(@http_post_content) build_response end |