Class: EventMachine::Protocols::HttpClient2::Request

### Home Classes Methods

### In Files

- lib/em/protocols/httpclient2.rb

### Parent

Object

### Methods

- ::new
- #receive_chunk_header
- #receive_chunk_trailer
- #receive_chunked_text
- #receive_header_line
- #receive_line
- #receive_sized_text
- #receive_text
- #send_request

### Included Modules

- EventMachine::Deferrable

### Files

- ChangeLog
- DEFERRABLES
- EPOLL
- INSTALL
- KEYBOARD
- LEGAL
- LIGHTWEIGHT_CONCURRENCY
- PURE_RUBY
- RELEASE_NOTES
- SMTP
- SPAWNED_PROCESSES
- TODO

### Class/Module Index

Quicksearch

- EventMachine
- EventMachine
- EventMachine::Channel
- EventMachine::Completion
- EventMachine::Connection
- EventMachine::DNS
- EventMachine::DNS::Request
- EventMachine::DNS::RequestIdAlreadyUsed
- EventMachine::DNS::Resolver
- EventMachine::DNS::Socket
- EventMachine::DatagramObject
- EventMachine::DefaultDeferrable
- EventMachine::Deferrable
- EventMachine::DeferrableChildProcess
- EventMachine::Error
- EventMachine::EvmaKeyboard
- EventMachine::EvmaTCPClient
- EventMachine::EvmaTCPServer
- EventMachine::EvmaUDPSocket
- EventMachine::EvmaUNIXClient
- EventMachine::EvmaUNIXServer
- EventMachine::FileNotFoundException
- EventMachine::FileStreamer
- EventMachine::FileWatch
- EventMachine::Iterator
- EventMachine::LoopbreakReader
- EventMachine::PeriodicTimer
- EventMachine::Pool
- EventMachine::ProcessWatch
- EventMachine::Protocols
- EventMachine::Protocols
- EventMachine::Protocols::HeaderAndContentProtocol
- EventMachine::Protocols::HttpClient
- EventMachine::Protocols::HttpClient2
- EventMachine::Protocols::HttpClient2::Request
- EventMachine::Protocols::LineAndTextProtocol
- EventMachine::Protocols::LineProtocol
- EventMachine::Protocols::LineText2
- EventMachine::Protocols::Memcache
- EventMachine::Protocols::Memcache::ParserError
- EventMachine::Protocols::ObjectProtocol
- EventMachine::Protocols::Postgres3
- EventMachine::Protocols::SASLauth
- EventMachine::Protocols::SASLauthclient
- EventMachine::Protocols::SmtpClient
- EventMachine::Protocols::SmtpServer
- EventMachine::Protocols::Socks4
- EventMachine::Protocols::Stomp
- EventMachine::Protocols::Stomp::Message
- EventMachine::Protocols::TcpConnectTester
- EventMachine::Queue
- EventMachine::Reactor
- EventMachine::Selectable
- EventMachine::SpawnedProcess
- EventMachine::StreamObject
- EventMachine::SystemCmd
- EventMachine::ThreadedResource
- EventMachine::TickLoop
- EventMachine::Timer
- EventMachine::UuidGenerator
- EventMachine::YieldBlockFromSpawnedProcess
- Object
- Object::EM
- Object::P
- BufferedTokenizer
- IO
- StringIO
- TestConnection

No matching classes.

# EventMachine::Protocols::HttpClient2::Request

@private

### Constants

ChunkedRE
ClenRE
ColonRE
HttpResponseRE

### Attributes

content[R]
header_lines[R]
headers[R]
internal_error[R]
status[R]
version[R]

### Public Class Methods

new(conn, args) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 65
    def initialize conn, args
      @conn = conn
      @args = args
      @header_lines = []
      @headers = {}
      @blanks = 0
      @chunk_trailer = nil
      @chunking = nil
    end

### Public Instance Methods

receive_chunk_header(ln) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 137
    def receive_chunk_header ln
      if ln.length > 0
        chunksize = ln.to_i(16)
        if chunksize > 0
          @conn.set_text_mode(ln.to_i(16))
        else
          @content = @content ? @content.join : ''
          @chunk_trailer = true
        end
      else
        # We correctly come here after each chunk gets read.
        # p "Got A BLANK chunk line"
      end

    end

receive_chunk_trailer(ln) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 102
    def receive_chunk_trailer ln
      if ln.length == 0
        @conn.pop_request
        succeed(self)
      else
        p "Received chunk trailer line"
      end
    end

receive_chunked_text(text) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 157
    def receive_chunked_text text
      # p "RECEIVED #{text.length} CHUNK"
      (@content ||= []) << text
    end

receive_header_line(ln) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 115
    def receive_header_line ln
      if ln.length == 0
        if @header_lines.length > 0
          process_header
        else
          @blanks += 1
          if @blanks > 10
            @conn.close_connection
          end
        end
      else
        @header_lines << ln
        if @header_lines.length > 100
          @internal_error = :bad_header
          @conn.close_connection
        end
      end
    end

receive_line(ln) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 90
    def receive_line ln
      if @chunk_trailer
        receive_chunk_trailer(ln)
      elsif @chunking
        receive_chunk_header(ln)
      else
        receive_header_line(ln)
      end
    end

receive_sized_text(text) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 232
    def receive_sized_text text
      @content = text
      @conn.pop_request
      succeed(self)
    end

receive_text(text) click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 224
    def receive_text text
      @chunking ? receive_chunked_text(text) : receive_sized_text(text)
    end

send_request() click to toggle source

    # File lib/em/protocols/httpclient2.rb, line 75
    def send_request
      az = @args[:authorization] and az = "Authorization: #{az}\r\n"

      r = [
        "#{@args[:verb]} #{@args[:uri]} HTTP/#{@args[:version] || "1.1"}\r\n",
        "Host: #{@args[:host_header] || "_"}\r\n",
        az || "",
          "\r\n"
      ]
      @conn.send_data r.join
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.