Class: Yup::RequestHandler

Inherits:
EM::Connection
  • Object
show all
Defined in:
lib/yup/request_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(forward_to, status_code, state, timeout) ⇒ RequestHandler

Returns a new instance of RequestHandler.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/yup/request_handler.rb', line 8

def initialize(forward_to, status_code, state, timeout)
  @forward_to  = forward_to
  @status_code = status_code
  @state       = state
  @timeout     = timeout

  @chunks = []

  @logger = Yup.logger.clone
  @logger.progname = "Yup::RequestHandler"
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



6
7
8
# File 'lib/yup/request_handler.rb', line 6

def queue
  @queue
end

Instance Method Details

#on_body(chunk) ⇒ Object



32
33
34
# File 'lib/yup/request_handler.rb', line 32

def on_body(chunk)
  @body << chunk
end

#on_message_beginObject



28
29
30
# File 'lib/yup/request_handler.rb', line 28

def on_message_begin
  @body = ''
end

#on_message_completeObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/yup/request_handler.rb', line 36

def on_message_complete
  @logger.info  {
    "Processing a new request: #{@parser.http_method} #{@parser.request_url} HTTP/#{@parser.http_version.join('.')}"
  }
  @logger.debug {
    "HTTP headers" + (@parser.headers.empty? ? " is empty" : "\n" + @parser.headers.inspect)
  }
  @logger.debug {
    "HTTP body"    + (@body.empty? ? " is empty" : "\n" + @body)
  }

  send_answer
  shedule_request
end

#post_initObject



20
21
22
# File 'lib/yup/request_handler.rb', line 20

def post_init
  @parser = Http::Parser.new(self)
end

#receive_data(data) ⇒ Object



24
25
26
# File 'lib/yup/request_handler.rb', line 24

def receive_data(data)
  @parser << data
end