Class: QNA::Request

Inherits:
Object
  • Object
show all
Extended by:
RequestInfoClassMethods
Includes:
RequestInfoMethods, ResponseMethods, RoutingMethods
Defined in:
lib/qna/request.rb

Overview

HTTP request

Constant Summary

Constants included from RequestInfoClassMethods

QNA::RequestInfoClassMethods::MAX_PARAMETER_NAME_SIZE, QNA::RequestInfoClassMethods::MAX_PARAMETER_VALUE_SIZE, QNA::RequestInfoClassMethods::PARAMETER_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestInfoClassMethods

parse_form_data, parse_multipart_form_data, parse_multipart_form_data_part, parse_multipart_form_data_part_headers, parse_urlencoded_form_data

Methods included from ResponseMethods

#redirect

Methods included from RoutingMethods

#is, #on, #on_accept, #on_get, #on_options, #on_post, #on_query_param, #on_root, #on_upgrade, #route, #route_found, #routing_path, #stop_routing

Methods included from RequestInfoMethods

#connection, #forwarded_for, #host, #method, #path, #protocol, #query, #query_string, #request_id, #scheme, #split_query_string, #upgrade_protocol, #uri

Constructor Details

#initialize(headers, adapter) ⇒ Request

Returns a new instance of Request.



19
20
21
22
# File 'lib/qna/request.rb', line 19

def initialize(headers, adapter)
  @headers  = headers
  @adapter  = adapter
end

Instance Attribute Details

#__next__Object

Returns the value of attribute __next__.



17
18
19
# File 'lib/qna/request.rb', line 17

def __next__
  @__next__
end

#adapterObject (readonly)

Returns the value of attribute adapter.



16
17
18
# File 'lib/qna/request.rb', line 16

def adapter
  @adapter
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/qna/request.rb', line 16

def headers
  @headers
end

Instance Method Details

#buffer_body_chunk(chunk) ⇒ Object



24
25
26
27
# File 'lib/qna/request.rb', line 24

def buffer_body_chunk(chunk)
  @buffered_body_chunks ||= []
  @buffered_body_chunks << chunk
end

#complete!(keep_alive = nil) ⇒ Object



51
52
53
54
# File 'lib/qna/request.rb', line 51

def complete!(keep_alive = nil)
  @message_complete = true
  @keep_alive = keep_alive
end

#complete?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/qna/request.rb', line 56

def complete?
  @message_complete
end

#consumeObject



60
61
62
# File 'lib/qna/request.rb', line 60

def consume
  @adapter.consume_request
end

#each_chunkObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/qna/request.rb', line 39

def each_chunk
  if @buffered_body_chunks
    while (chunk = @buffered_body_chunks.shift)
      yield chunk
    end
    @buffered_body_chunks = nil
  end
  while !@message_complete && (chunk = @adapter.get_body_chunk)
    yield chunk
  end
end

#finishObject



97
98
99
100
101
# File 'lib/qna/request.rb', line 97

def finish
  send_headers({}) unless @headers_sent
  
  @adapter.finish
end

#headers_sent?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/qna/request.rb', line 103

def headers_sent?
  @headers_sent
end

#keep_alive?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/qna/request.rb', line 64

def keep_alive?
  @keep_alive
end

#next_chunkObject



29
30
31
32
33
34
35
36
37
# File 'lib/qna/request.rb', line 29

def next_chunk
  if @buffered_body_chunks
    chunk = @buffered_body_chunks.shift
    @buffered_body_chunks = nil if @buffered_body_chunks.empty?
    return chunk
  end

  @message_complete ? nil : @adapter.get_body_chunk
end

#readObject Also known as: body



68
69
70
71
72
73
74
75
# File 'lib/qna/request.rb', line 68

def read
  buf = @buffered_body_chunks ? @buffered_body_chunks.join : nil
  while (chunk = @adapter.get_body_chunk)
    (buf ||= +'') << chunk
  end
  @buffered_body_chunks = nil
  buf
end

#respond(body, headers = {}) ⇒ Object



78
79
80
81
# File 'lib/qna/request.rb', line 78

def respond(body, headers = {})
  @adapter.respond(body, headers)
  @headers_sent = true
end

#send_chunk(body, done: false) ⇒ Object Also known as: <<



90
91
92
93
94
# File 'lib/qna/request.rb', line 90

def send_chunk(body, done: false)
  send_headers({}) unless @headers_sent
  
  @adapter.send_chunk(body, done: done)
end

#send_headers(headers = {}, empty_response = false) ⇒ Object



83
84
85
86
87
88
# File 'lib/qna/request.rb', line 83

def send_headers(headers = {}, empty_response = false)
  return if @headers_sent
  
  @headers_sent = true
  @adapter.send_headers(headers, empty_response: empty_response)
end