Class: TestHttpClient::PostContent
- Inherits:
-
EventMachine::Protocols::LineAndTextProtocol
- Object
- EventMachine::Connection
- EventMachine::Protocols::LineAndTextProtocol
- TestHttpClient::PostContent
- Defined in:
- lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb
Overview
Constant Summary
Constants inherited from EventMachine::Protocols::LineAndTextProtocol
EventMachine::Protocols::LineAndTextProtocol::MaxBinaryLength, EventMachine::Protocols::LineAndTextProtocol::MaxLineLength
Instance Attribute Summary
Attributes inherited from EventMachine::Connection
Instance Method Summary collapse
-
#initialize(*args) ⇒ PostContent
constructor
A new instance of PostContent.
- #process_headers ⇒ Object
- #receive_binary_data(data) ⇒ Object
- #receive_line(line) ⇒ Object
- #send_response ⇒ Object
Methods inherited from EventMachine::Protocols::LineAndTextProtocol
#receive_data, #set_binary_mode, #unbind
Methods inherited from EventMachine::Connection
#associate_callback_target, #close_connection, #close_connection_after_writing, #comm_inactivity_timeout, #comm_inactivity_timeout=, #connection_completed, #detach, #error?, #get_outbound_data_size, #get_peer_cert, #get_peername, #get_pid, #get_sock_opt, #get_sockname, #get_status, new, #notify_readable=, #notify_readable?, #notify_writable=, #notify_writable?, #pause, #paused?, #pending_connect_timeout, #pending_connect_timeout=, #post_init, #proxy_incoming_to, #proxy_target_unbound, #receive_data, #reconnect, #resume, #send_data, #send_datagram, #send_file_data, #set_comm_inactivity_timeout, #set_pending_connect_timeout, #ssl_handshake_completed, #ssl_verify_peer, #start_tls, #stop_proxying, #stream_file_data, #unbind
Constructor Details
#initialize(*args) ⇒ PostContent
Returns a new instance of PostContent.
119 120 121 122 |
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb', line 119 def initialize *args super @lines = [] end |
Instance Method Details
#process_headers ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb', line 134 def process_headers if @lines.first =~ /\APOST ([^\s]+) HTTP\/1.1\Z/ @uri = $1.dup else raise "bad request" end @lines.each {|line| if line =~ /\AContent-length:\s*(\d+)\Z/i @content_length = $1.dup.to_i elsif line =~ /\AContent-type:\s*(\d+)\Z/i @content_type = $1.dup end } raise "invalid content length" unless @content_length set_binary_mode @content_length end |
#receive_binary_data(data) ⇒ Object
130 131 132 133 |
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb', line 130 def receive_binary_data data @post_content = data send_response end |
#receive_line(line) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb', line 123 def receive_line line if line.length > 0 @lines << line else process_headers end end |
#send_response ⇒ Object
152 153 154 155 |
# File 'lib/ext/eventmachine-0.12.10/tests/test_httpclient.rb', line 152 def send_response send_data "HTTP/1.1 200 ...\r\nConnection: close\r\nContent-length: 10\r\nContent-type: text/html\r\n\r\n0123456789" close_connection_after_writing end |