Class: Gloo::WebSvr::Request

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(engine, handler, env = nil) ⇒ Request

Set up the web server.



38
39
40
41
42
43
44
45
46
47
# File 'lib/gloo/web_svr/request.rb', line 38

def initialize( engine, handler, env = nil )
  @engine = engine
  @log = @engine.log
  @request_params = RequestParams.new( @log )

  @handler = handler

  @env = env
  detect_env
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



27
28
29
# File 'lib/gloo/web_svr/request.rb', line 27

def db
  @db
end

#elapsedObject (readonly)

Returns the value of attribute elapsed.



27
28
29
# File 'lib/gloo/web_svr/request.rb', line 27

def elapsed
  @elapsed
end

#hostObject (readonly)

Returns the value of attribute host.



26
27
28
# File 'lib/gloo/web_svr/request.rb', line 26

def host
  @host
end

#ipObject (readonly)

Returns the value of attribute ip.



26
27
28
# File 'lib/gloo/web_svr/request.rb', line 26

def ip
  @ip
end

#methodObject (readonly)

Returns the value of attribute method.



26
27
28
# File 'lib/gloo/web_svr/request.rb', line 26

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/gloo/web_svr/request.rb', line 26

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



26
27
28
# File 'lib/gloo/web_svr/request.rb', line 26

def query
  @query
end

#request_paramsObject

Returns the value of attribute request_params.



28
29
30
# File 'lib/gloo/web_svr/request.rb', line 28

def request_params
  @request_params
end

Instance Method Details

#detect_envObject

Write the request information to the log.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gloo/web_svr/request.rb', line 82

def detect_env
  req = Rack::Request.new( @env )

  @method = req.request_method
  @path = req.path
  @host = req.host_with_port
  @query = req.query_string

  @request_params.init_query_params( @query )
  @ip = req.ip
  @handler.server_obj.session.set_session_data_for_request( @env )

  @request_params.init_body_params( @env[ 'rack.input' ].read )
  @method = @request_params.get_body_method_override @method
end

#finish_timerObject

Write the request completion time to the log.



114
115
116
117
118
119
# File 'lib/gloo/web_svr/request.rb', line 114

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

#logObject

Write the request information to the log.



129
130
131
132
133
# File 'lib/gloo/web_svr/request.rb', line 129

def log
  @log.info "#{@method} #{@host}#{@path}"

  @request_params.log_params
end

#processObject

Process the request and return a result.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gloo/web_svr/request.rb', line 57

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

#start_timerObject

Keep track of the request start time.



106
107
108
109
# File 'lib/gloo/web_svr/request.rb', line 106

def start_timer
  @start = Time.now
  @engine.running_app.reset_db_time
end