Sha256: a06ad57970995ccb5a072578b870a5eb66cdb6e431b4316e8063ea5a5b355bac

Contents?: true

Size: 1017 Bytes

Versions: 31

Compression:

Stored size: 1017 Bytes

Contents

module HTTP
  class Response
    class Parser
      attr_reader :headers

      def initialize
        @parser = HTTP::Parser.new(self)
        reset
      end

      def add(data)
        @parser << data
      end
      alias_method :<<, :add

      def headers?
        !!@headers
      end

      def http_version
        @parser.http_version.join(".")
      end

      def status_code
        @parser.status_code
      end

      #
      # HTTP::Parser callbacks
      #

      def on_headers_complete(headers)
        @headers = headers
      end

      def on_body(chunk)
        if @chunk
          @chunk << chunk
        else
          @chunk = chunk
        end
      end

      def chunk
        chunk, @chunk = @chunk, nil
        chunk
      end

      def on_message_complete
        @finished = true
      end

      def reset
        @parser.reset!

        @finished = false
        @headers  = nil
        @chunk    = nil
      end

      def finished?
        @finished
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
http-0.9.9 lib/http/response/parser.rb
http-0.9.8 lib/http/response/parser.rb
http-0.9.7 lib/http/response/parser.rb
http-0.9.6 lib/http/response/parser.rb
http-0.9.5 lib/http/response/parser.rb
http-0.9.4 lib/http/response/parser.rb
http-0.9.3 lib/http/response/parser.rb
http-0.8.14 lib/http/response/parser.rb
http-0.9.2 lib/http/response/parser.rb
http-0.8.13 lib/http/response/parser.rb
http-0.9.1 lib/http/response/parser.rb
http-0.9.0 lib/http/response/parser.rb
http-0.9.0.pre lib/http/response/parser.rb
http-0.8.12 lib/http/response/parser.rb
http-0.8.11 lib/http/response/parser.rb
http-0.8.10 lib/http/response/parser.rb
http-0.8.9 lib/http/response/parser.rb
http-0.8.8 lib/http/response/parser.rb
http-0.8.7 lib/http/response/parser.rb
http-0.8.6 lib/http/response/parser.rb