Class: Gloo::WebSvr::Request
- Inherits:
-
Object
- Object
- Gloo::WebSvr::Request
- Defined in:
- lib/gloo/web_svr/request.rb
Constant Summary collapse
- REQUEST_METHOD =
'REQUEST_METHOD'.freeze
- REQUEST_PATH =
'REQUEST_PATH'.freeze
- HTTP_HOST =
'HTTP_HOST'.freeze
- QUERY_STRING =
'QUERY_STRING'.freeze
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#elapsed ⇒ Object
readonly
Returns the value of attribute elapsed.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#id ⇒ Object
Returns the value of attribute id.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#body_params ⇒ Object
Get the hash of body parameters.
-
#check_body_method ⇒ Object
Check the body to see if there is a PATCH or a PUT in the method override.
-
#detect_env ⇒ Object
Write the request information to the log.
-
#finish_timer ⇒ Object
Write the request completion time to the log.
-
#initialize(engine, handler, env = nil) ⇒ Request
constructor
Set up the web server.
-
#log ⇒ Object
Write the request information to the log.
-
#process ⇒ Object
Process the request and return a result.
-
#query_params ⇒ Object
Get the hash of query parameters.
-
#start_timer ⇒ Object
Keep track of the request start time.
Constructor Details
#initialize(engine, handler, env = nil) ⇒ Request
Set up the web server.
38 39 40 41 42 43 44 45 46 |
# File 'lib/gloo/web_svr/request.rb', line 38 def initialize( engine, handler, env = nil ) @engine = engine @log = @engine.log @handler = handler @env = env detect_env end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
26 27 28 |
# File 'lib/gloo/web_svr/request.rb', line 26 def body @body end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
27 28 29 |
# File 'lib/gloo/web_svr/request.rb', line 27 def db @db end |
#elapsed ⇒ Object (readonly)
Returns the value of attribute elapsed.
27 28 29 |
# File 'lib/gloo/web_svr/request.rb', line 27 def elapsed @elapsed end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
26 27 28 |
# File 'lib/gloo/web_svr/request.rb', line 26 def host @host end |
#id ⇒ Object
Returns the value of attribute id.
28 29 30 |
# File 'lib/gloo/web_svr/request.rb', line 28 def id @id end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
26 27 28 |
# File 'lib/gloo/web_svr/request.rb', line 26 def ip @ip end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
26 27 28 |
# File 'lib/gloo/web_svr/request.rb', line 26 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/gloo/web_svr/request.rb', line 26 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
26 27 28 |
# File 'lib/gloo/web_svr/request.rb', line 26 def query @query end |
Instance Method Details
#body_params ⇒ Object
Get the hash of body parameters.
151 152 153 |
# File 'lib/gloo/web_svr/request.rb', line 151 def body_params return @body ? @body : {} end |
#check_body_method ⇒ Object
Check the body to see if there is a PATCH or a PUT in the method override.
134 135 136 137 138 |
# File 'lib/gloo/web_svr/request.rb', line 134 def check_body_method if @body[ '_method' ] @method = @body[ '_method' ].upcase end end |
#detect_env ⇒ Object
Write the request information to the log.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/gloo/web_svr/request.rb', line 81 def detect_env req = Rack::Request.new( @env ) @method = req.request_method @path = req.path @host = req.host_with_port @query = req.query_string @ip = req.ip # @method = @env[ REQUEST_METHOD ] # @path = @env[ REQUEST_PATH ] # @host = @env[ HTTP_HOST ] # @query = @env[ QUERY_STRING ] @handler.server_obj.session.set_session_data_for_request( @env ) @body = @env[ 'rack.input' ].read @body = Rack::Utils.parse_query @body check_body_method end |
#finish_timer ⇒ Object
Write the request completion time to the log.
118 119 120 121 122 123 |
# File 'lib/gloo/web_svr/request.rb', line 118 def finish_timer @finish = Time.now @elapsed = ( ( @finish - @start ) * 1000.0 ).round(2) @db = @engine.running_app.db_time @log.info "*** Web request complete. DB: #{@db} ms. Elapsed time: #{@elapsed} ms" end |
#log ⇒ Object
Write the request information to the log.
158 159 160 161 162 |
# File 'lib/gloo/web_svr/request.rb', line 158 def log @log.info "#{@method} #{@host}#{@path}" @log.info "Parameters: #{@query}" @log.info "Body: #{@body}" unless @body.empty? end |
#process ⇒ Object
Process the request and return a result.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gloo/web_svr/request.rb', line 56 def process start_timer # Run the on_request script if there is one. @handler.server_obj.set_request_data self @handler.server_obj.run_on_request result, page_obj = @handler.handle self finish_timer # Run the on_response script if there is one. @handler.server_obj.set_response_data( self, result, page_obj ) @handler.server_obj.run_on_response return result end |
#query_params ⇒ Object
Get the hash of query parameters.
143 144 145 146 |
# File 'lib/gloo/web_svr/request.rb', line 143 def query_params return {} unless @query return Rack::Utils.parse_query( @query ) end |
#start_timer ⇒ Object
Keep track of the request start time.
110 111 112 113 |
# File 'lib/gloo/web_svr/request.rb', line 110 def start_timer @start = Time.now @engine.running_app.reset_db_time end |