Class: DripDrop::Mongrel2Handler
- Inherits:
-
ZMQBaseHandler
- Object
- BaseHandler
- ZMQBaseHandler
- DripDrop::Mongrel2Handler
- Includes:
- ZMQReadableHandler, ZMQWritableHandler
- Defined in:
- lib/dripdrop/handlers/mongrel2.rb
Constant Summary collapse
- StatusMessage =
From WEBrick
{ 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Request Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported' }
Instance Attribute Summary collapse
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Attributes included from ZMQReadableHandler
Attributes inherited from ZMQBaseHandler
Instance Method Summary collapse
- #add_connection(connection) ⇒ Object
- #address ⇒ Object
- #http_response(body, code, headers) ⇒ Object
-
#initialize(*args) ⇒ Mongrel2Handler
constructor
A new instance of Mongrel2Handler.
- #on_readable(socket, messages) ⇒ Object
- #read_connection ⇒ Object
- #reply(req, msg) ⇒ Object
- #reply_http(req, body, code = 200, headers = {}) ⇒ Object
- #send_resp(uuid, conn_id, msg) ⇒ Object
- #write_connection ⇒ Object
Methods included from ZMQReadableHandler
Methods included from ZMQWritableHandler
Methods inherited from ZMQBaseHandler
#on_receive, #on_recv, #post_setup
Methods inherited from BaseHandler
#handle_error, #on_error, #print_exception
Constructor Details
#initialize(*args) ⇒ Mongrel2Handler
Returns a new instance of Mongrel2Handler.
36 37 38 39 40 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 36 def initialize(*args) super(*args) @connections = [] self.uuid = @opts[:uuid] end |
Instance Attribute Details
#uuid ⇒ Object
Returns the value of attribute uuid.
34 35 36 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 34 def uuid @uuid end |
Instance Method Details
#add_connection(connection) ⇒ Object
42 43 44 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 42 def add_connection(connection) @connections << connection end |
#address ⇒ Object
54 55 56 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 54 def address raise "Not applicable for a Mongrel2Handler" end |
#http_response(body, code, headers) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 77 def http_response(body, code, headers) headers['Content-Length'] = body.size headers_s = headers.map { |k, v| "%s: %s" % [k, v] }.join("\r\n") "HTTP/1.1 #{code} #{StatusMessage[code.to_i]}\r\n#{headers_s}\r\n\r\n#{body}" end |
#on_readable(socket, messages) ⇒ Object
58 59 60 61 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 58 def on_readable(socket, ) req = Mongrel2Request.parse_request([0]) @recv_cbak.call(req) end |
#read_connection ⇒ Object
46 47 48 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 46 def read_connection @connections[0] end |
#reply(req, msg) ⇒ Object
69 70 71 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 69 def reply(req, msg) self.send_resp(req.sender, req.conn_id, msg) end |
#reply_http(req, body, code = 200, headers = {}) ⇒ Object
73 74 75 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 73 def reply_http(req, body, code=200, headers={}) self.reply(req, http_response(body, code, headers)) end |
#send_resp(uuid, conn_id, msg) ⇒ Object
63 64 65 66 67 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 63 def send_resp(uuid, conn_id, msg) header = "%s %d:%s," % [uuid, conn_id.size, conn_id] string = header + ' ' + msg (string) end |
#write_connection ⇒ Object
50 51 52 |
# File 'lib/dripdrop/handlers/mongrel2.rb', line 50 def write_connection @connections[1] end |