Class: EventMachine::Protocols::HeaderAndContentProtocol
- Inherits:
-
LineAndTextProtocol
- Object
- Connection
- LineAndTextProtocol
- EventMachine::Protocols::HeaderAndContentProtocol
- Defined in:
- lib/protocols/header_and_content.rb
Constant Summary collapse
- ContentLengthPattern =
/Content-length:\s*(\d+)/i
Constants inherited from LineAndTextProtocol
LineAndTextProtocol::MaxBinaryLength, LineAndTextProtocol::MaxLineLength
Instance Attribute Summary
Attributes inherited from Connection
Class Method Summary collapse
Instance Method Summary collapse
-
#headers_2_hash(hdrs) ⇒ Object
Basically a convenience method.
-
#initialize(*args) ⇒ HeaderAndContentProtocol
constructor
A new instance of HeaderAndContentProtocol.
- #receive_binary_data(text) ⇒ Object
- #receive_line(line) ⇒ Object
Methods inherited from LineAndTextProtocol
#receive_data, #set_binary_mode, #unbind
Methods inherited from Connection
#close_connection, #close_connection_after_writing, #comm_inactivity_timeout, #comm_inactivity_timeout=, #connection_completed, #get_peername, #get_pid, #post_init, #receive_data, #reconnect, #send_data, #send_datagram, #send_file_data, #set_comm_inactivity_timeout, #start_tls, #stream_file_data, #unbind
Constructor Details
#initialize(*args) ⇒ HeaderAndContentProtocol
Returns a new instance of HeaderAndContentProtocol.
35 36 37 38 |
# File 'lib/protocols/header_and_content.rb', line 35 def initialize *args super init_for_request end |
Class Method Details
.headers_2_hash(hdrs) ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/protocols/header_and_content.rb', line 108 def headers_2_hash hdrs hash = {} hdrs.each {|h| if /\A([^\s:]+)\s*:\s*/ =~ h tail = $'.dup hash[ $1.downcase.gsub(/-/,"_").intern ] = tail end } hash end |
Instance Method Details
#headers_2_hash(hdrs) ⇒ Object
Basically a convenience method. We might create a subclass that does this automatically. But it’s such a performance killer.
103 104 105 |
# File 'lib/protocols/header_and_content.rb', line 103 def headers_2_hash hdrs self.class.headers_2_hash hdrs end |
#receive_binary_data(text) ⇒ Object
76 77 78 79 |
# File 'lib/protocols/header_and_content.rb', line 76 def receive_binary_data text @hc_content = text dispatch_request end |
#receive_line(line) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/protocols/header_and_content.rb', line 40 def receive_line line case @hc_mode when :discard_blanks unless line == "" @hc_mode = :headers receive_line line end when :headers if line == "" raise "unrecognized state" unless @hc_headers.length > 0 if respond_to?(:receive_headers) receive_headers @hc_headers end # @hc_content_length will be nil, not 0, if there was no content-length header. if @hc_content_length.to_i > 0 set_binary_mode @hc_content_length else dispatch_request end else @hc_headers << line if ContentLengthPattern =~ line # There are some attacks that rely on sending multiple content-length # headers. This is a crude protection, but needs to become tunable. raise "extraneous content-length header" if @hc_content_length @hc_content_length = $1.to_i end if @hc_headers.length == 1 and respond_to?(:receive_first_header_line) receive_first_header_line line end end else raise "internal error, unsupported mode" end end |