diff options
Diffstat (limited to 'lib/plum/http_connection.rb')
-rw-r--r-- | lib/plum/http_connection.rb | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/plum/http_connection.rb b/lib/plum/http_connection.rb index 45c6486..1c30e6e 100644 --- a/lib/plum/http_connection.rb +++ b/lib/plum/http_connection.rb @@ -3,12 +3,28 @@ using Plum::BinaryString module Plum class HTTPConnection < Connection - def initialize(io, local_settings = {}) + attr_reader :sock + + def initialize(sock, local_settings = {}) require "http/parser" - super @_headers = nil @_body = String.new @_http_parser = setup_parser + @sock = sock + super(@sock.method(:write), local_settings) + end + + # Starts communication with the peer. It blocks until the io is closed, or reaches EOF. + def run + while !@sock.closed? && !@sock.eof? + self << @sock.readpartial(1024) + end + end + + # Closes the socket. + def close + super + @sock.close end private @@ -56,7 +72,7 @@ module Plum "Server: plum/#{Plum::VERSION}\r\n" "\r\n" - io.write(resp) + @sock.write(resp) end def process_first_request |