lib/gloo/web_svr/request.rb in gloo-3.3.0 vs lib/gloo/web_svr/request.rb in gloo-3.4.0

- old
+ new

@@ -1,27 +1,32 @@ # Author:: Eric Crane (mailto:eric.crane@mac.com) -# Copyright:: Copyright (c) 20124 Eric Crane. All rights reserved. +# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved. # # A web Request for a page, action, or static resource. # # Kinds of Resources # Web Page # Action - does something and redirects to a page (or returns nothing) # API - returns JSON instead of HTML (but is that different from Web Page?) # Static Resource - File, PDF, Image, etc. # +# +# See More doc here: +# https://www.rubydoc.info/gems/rack/Rack/Request/Helpers#path-instance_method +# module Gloo module WebSvr class Request REQUEST_METHOD = 'REQUEST_METHOD'.freeze REQUEST_PATH = 'REQUEST_PATH'.freeze HTTP_HOST = 'HTTP_HOST'.freeze QUERY_STRING = 'QUERY_STRING'.freeze - attr_reader :method, :host, :path, :query, :body + attr_reader :method, :host, :path, :query, :body, :ip + attr_reader :db, :elapsed attr_accessor :id # --------------------------------------------------------------------- # Initialization @@ -48,28 +53,49 @@ # # Process the request and return a result. # 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 = @handler.handle self finish_timer + + # Run the on_response script if there is one. + @handler.server_obj.set_response_data self, result + @handler.server_obj.run_on_response + return result end + # --------------------------------------------------------------------- # ENV # --------------------------------------------------------------------- # # Write the request information to the log. # def detect_env - @method = @env[ REQUEST_METHOD ] - @path = @env[ REQUEST_PATH ] - @host = @env[ HTTP_HOST ] - @query = @env[ QUERY_STRING ] + 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 @@ -90,11 +116,11 @@ # Write the request completion time to the log. # 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" + @db = @engine.running_app.db_time + @log.info "*** Web request complete. DB: #{@db} ms. Elapsed time: #{@elapsed} ms" end # --------------------------------------------------------------------- # Helper functions