Class: Baykit::BayServer::Tours::TourReq
- Inherits:
-
Object
- Object
- Baykit::BayServer::Tours::TourReq
- Includes:
- Baykit::BayServer, Protocol, Util, Util::Reusable
- Defined in:
- lib/baykit/bayserver/tours/tour_req.rb
Instance Attribute Summary collapse
-
#available ⇒ Object
readonly
Returns the value of attribute available.
-
#bytes_consumed ⇒ Object
readonly
Returns the value of attribute bytes_consumed.
-
#bytes_limit ⇒ Object
readonly
Returns the value of attribute bytes_limit.
-
#bytes_posted ⇒ Object
readonly
Request content info.
-
#charset ⇒ Object
Returns the value of attribute charset.
-
#content_handler ⇒ Object
readonly
Returns the value of attribute content_handler.
-
#ended ⇒ Object
readonly
Returns the value of attribute ended.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#key ⇒ Object
readonly
request id in FCGI or stream id in HTTP/2.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path_info ⇒ Object
Returns the value of attribute path_info.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#query_string ⇒ Object
Returns the value of attribute query_string.
-
#remote_address ⇒ Object
Returns the value of attribute remote_address.
-
#remote_host_func ⇒ Object
function.
-
#remote_pass ⇒ Object
Returns the value of attribute remote_pass.
-
#remote_port ⇒ Object
Returns the value of attribute remote_port.
-
#remote_user ⇒ Object
Returns the value of attribute remote_user.
-
#req_host ⇒ Object
from Host header.
-
#req_port ⇒ Object
from Host header.
-
#rewritten_uri ⇒ Object
set if URI is rewritten.
-
#script_name ⇒ Object
Returns the value of attribute script_name.
-
#server_address ⇒ Object
Returns the value of attribute server_address.
-
#server_name ⇒ Object
Returns the value of attribute server_name.
-
#server_port ⇒ Object
Returns the value of attribute server_port.
-
#tour ⇒ Object
readonly
Request Header info.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #abort ⇒ Object
- #buffer_available ⇒ Object
- #consumed(chk_id, length, &callback) ⇒ Object
- #end_req_content(check_id) ⇒ Object
- #init(key) ⇒ Object
-
#initialize(tur) ⇒ TourReq
constructor
A new instance of TourReq.
- #post_req_content(check_id, data, start, len, &callback) ⇒ Object
-
#remote_host ⇒ Object
other methods.
-
#reset ⇒ Object
Implements Reusable.
- #set_content_handler(hnd) ⇒ Object
- #set_limit(limit) ⇒ Object
Constructor Details
Instance Attribute Details
#available ⇒ Object (readonly)
Returns the value of attribute available.
55 56 57 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 55 def available @available end |
#bytes_consumed ⇒ Object (readonly)
Returns the value of attribute bytes_consumed.
52 53 54 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 52 def bytes_consumed @bytes_consumed end |
#bytes_limit ⇒ Object (readonly)
Returns the value of attribute bytes_limit.
53 54 55 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 53 def bytes_limit @bytes_limit end |
#bytes_posted ⇒ Object (readonly)
Request content info
Handling request contents
51 52 53 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 51 def bytes_posted @bytes_posted end |
#charset ⇒ Object
Returns the value of attribute charset.
43 44 45 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 43 def charset @charset end |
#content_handler ⇒ Object (readonly)
Returns the value of attribute content_handler.
45 46 47 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 45 def content_handler @content_handler end |
#ended ⇒ Object (readonly)
Returns the value of attribute ended.
56 57 58 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 56 def ended @ended end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
25 26 27 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 25 def headers @headers end |
#key ⇒ Object (readonly)
request id in FCGI or stream id in HTTP/2
19 20 21 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 19 def key @key end |
#method ⇒ Object
Returns the value of attribute method.
23 24 25 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 23 def method @method end |
#path_info ⇒ Object
Returns the value of attribute path_info.
29 30 31 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 29 def path_info @path_info end |
#protocol ⇒ Object
Returns the value of attribute protocol.
22 23 24 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 22 def protocol @protocol end |
#query_string ⇒ Object
Returns the value of attribute query_string.
28 29 30 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 28 def query_string @query_string end |
#remote_address ⇒ Object
Returns the value of attribute remote_address.
37 38 39 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 37 def remote_address @remote_address end |
#remote_host_func ⇒ Object
function
39 40 41 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 39 def remote_host_func @remote_host_func end |
#remote_pass ⇒ Object
Returns the value of attribute remote_pass.
35 36 37 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 35 def remote_pass @remote_pass end |
#remote_port ⇒ Object
Returns the value of attribute remote_port.
38 39 40 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 38 def remote_port @remote_port end |
#remote_user ⇒ Object
Returns the value of attribute remote_user.
34 35 36 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 34 def remote_user @remote_user end |
#req_host ⇒ Object
from Host header
31 32 33 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 31 def req_host @req_host end |
#req_port ⇒ Object
from Host header
32 33 34 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 32 def req_port @req_port end |
#rewritten_uri ⇒ Object
set if URI is rewritten
27 28 29 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 27 def rewritten_uri @rewritten_uri end |
#script_name ⇒ Object
Returns the value of attribute script_name.
30 31 32 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 30 def script_name @script_name end |
#server_address ⇒ Object
Returns the value of attribute server_address.
40 41 42 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 40 def server_address @server_address end |
#server_name ⇒ Object
Returns the value of attribute server_name.
42 43 44 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 42 def server_name @server_name end |
#server_port ⇒ Object
Returns the value of attribute server_port.
41 42 43 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 41 def server_port @server_port end |
#tour ⇒ Object (readonly)
Request Header info
18 19 20 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 18 def tour @tour end |
#uri ⇒ Object
Returns the value of attribute uri.
21 22 23 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 21 def uri @uri end |
Instance Method Details
#abort ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 202 def abort BayLog.debug("%s abort", @tour) if @tour.preparing? #@tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED) return true elsif @tour.running? aborted = true if @content_handler != nil aborted = @content_handler.on_abort_req(@tour) end #if aborted # @tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::ABORTED) #end return aborted else BayLog.debug("%s tour is not preparing or not running", @tour) return false end end |
#buffer_available ⇒ Object
237 238 239 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 237 def buffer_available() return @bytes_posted - @bytes_consumed < BayServer.harbor.tour_buffer_size end |
#consumed(chk_id, length, &callback) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 182 def consumed(chk_id, length, &callback) @tour.check_tour_id(chk_id) @bytes_consumed += length BayLog.debug("%s reqConsumed: len=%d posted=%d limit=%d consumed=%d", @tour, length, @bytes_posted, @bytes_limit, @bytes_consumed) resume = false old_available = @available if buffer_available() @available = true end if !old_available && @available BayLog.debug("%s request available (^o^): posted=%d consumed=%d", self, @bytes_posted, @bytes_consumed); resume = true end callback.call(length, resume) end |
#end_req_content(check_id) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 165 def end_req_content(check_id) @tour.check_tour_id(check_id) if @ended raise Sink.new("#{@tour} Request content is already ended") end @tour.change_state(Tour::TOUR_ID_NOCHECK, Tour::TourState::RUNNING) if @bytes_limit >= 0 && @bytes_posted != @bytes_limit raise ProtocolException.new("Read data exceed content-length: #{@bytes_posted}/#{@bytes_limit}") end if @content_handler != nil @content_handler.on_end_req_content(@tour) end @ended = true end |
#init(key) ⇒ Object
63 64 65 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 63 def init(key) @key = key end |
#post_req_content(check_id, data, start, len, &callback) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 123 def post_req_content(check_id, data, start, len, &callback) @tour.check_tour_id(check_id) data_passed = false if @tour.error != nil # If has error, only read content. (Do not call content handler) BayLog.debug("%s tour has error.", @tour) elsif !@tour.reading? raise HttpException.new(HttpStatus.BAD_REQUEST, "%s tour is not reading.", @tour) elsif @content_handler == nil BayLog.warn("%s content read, but no content handler", tour) elsif @bytes_posted + len > @bytes_limit raise ProtocolException.new("Read data exceed content-length: %d/%d", @bytes_posted + len, @bytes_limit) else @content_handler.on_read_req_content(@tour, data, start, len, &callback) data_passed = true end @bytes_posted += len BayLog.debug("%s post req content: len=%d posted=%d limit=%d consumed=%d", @tour, len, @bytes_posted, @bytes_limit, @bytes_consumed) if !data_passed return true end old_available = @available if !buffer_available() @available = false end if old_available && !@available BayLog.debug("%s request unavailable (_ _): posted=%d consumed=%d", self, @bytes_posted, @bytes_consumed); end return @available end |
#remote_host ⇒ Object
other methods
109 110 111 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 109 def remote_host return @remote_host_func.call() end |
#reset ⇒ Object
Implements Reusable
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 70 def reset() @headers.clear @uri = nil @method = nil @protocol = nil @bytes_posted = 0 @bytes_consumed = 0 @bytes_limit = 0 @key = 0 @rewritten_uri = nil @query_string = nil @path_info = nil @script_name = nil @req_host = nil @req_port = 0 @remote_user = nil @remote_pass = nil @remote_address = nil @remote_port = 0 @remote_host_func = nil @server_address = nil @server_port = 0 @server_name = nil @charset = nil @available = false @content_handler = nil @ended = false end |
#set_content_handler(hnd) ⇒ Object
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/baykit/bayserver/tours/tour_req.rb', line 226 def set_content_handler(hnd) if hnd == nil raise Sink.new("nil") end if @content_handler != nil raise Sink.new("content handler already set") end @content_handler = hnd end |