gloo 3.4.1 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/lib/VERSION +1 -1
- data/lib/VERSION_NOTES +15 -0
- data/lib/gloo/app/args.rb +2 -2
- data/lib/gloo/app/engine.rb +21 -2
- data/lib/gloo/app/info.rb +0 -2
- data/lib/gloo/convert/converter.rb +1 -2
- data/lib/gloo/convert/string_to_integer.rb +2 -0
- data/lib/gloo/core/dictionary.rb +1 -1
- data/lib/gloo/core/event_manager.rb +19 -0
- data/lib/gloo/core/factory.rb +2 -2
- data/lib/gloo/core/gloo_system.rb +1 -1
- data/lib/gloo/core/here.rb +1 -1
- data/lib/gloo/core/obj.rb +61 -5
- data/lib/gloo/core/parser.rb +1 -1
- data/lib/gloo/core/pn.rb +1 -1
- data/lib/gloo/exec/dispatch.rb +19 -0
- data/lib/gloo/exec/runner.rb +1 -1
- data/lib/gloo/objs/basic/integer.rb +10 -1
- data/lib/gloo/objs/ctrl/each.rb +17 -184
- data/lib/gloo/objs/ctrl/each_child.rb +68 -0
- data/lib/gloo/objs/ctrl/each_file.rb +83 -0
- data/lib/gloo/objs/ctrl/each_line.rb +67 -0
- data/lib/gloo/objs/ctrl/each_repo.rb +84 -0
- data/lib/gloo/objs/ctrl/each_word.rb +67 -0
- data/lib/gloo/objs/data/mysql.rb +2 -2
- data/lib/gloo/objs/data/pg.rb +1 -1
- data/lib/gloo/objs/data/query.rb +54 -5
- data/lib/gloo/objs/data/query_result.rb +6 -1
- data/lib/gloo/objs/data/sqlite.rb +1 -1
- data/lib/gloo/objs/data/table.rb +2 -2
- data/lib/gloo/objs/ror/eval.rb +1 -1
- data/lib/gloo/objs/security/password.rb +5 -8
- data/lib/gloo/objs/system/file_handle.rb +39 -5
- data/lib/gloo/objs/web_svr/element.rb +2 -2
- data/lib/gloo/objs/web_svr/page.rb +16 -6
- data/lib/gloo/objs/web_svr/svr.rb +29 -13
- data/lib/gloo/persist/file_loader.rb +2 -2
- data/lib/gloo/persist/file_storage.rb +1 -1
- data/lib/gloo/persist/line_splitter.rb +1 -0
- data/lib/gloo/verbs/check.rb +54 -0
- data/lib/gloo/verbs/redirect.rb +34 -2
- data/lib/gloo/verbs/tell.rb +11 -36
- data/lib/gloo/web_svr/handler.rb +32 -5
- data/lib/gloo/web_svr/request.rb +11 -40
- data/lib/gloo/web_svr/request_params.rb +104 -0
- data/lib/gloo/web_svr/response.rb +25 -0
- data/lib/gloo/web_svr/response_code.rb +1 -1
- data/lib/gloo/web_svr/routing/router.rb +10 -2
- data/lib/gloo/web_svr/session.rb +18 -12
- metadata +10 -3
@@ -114,14 +114,22 @@ module Gloo
|
|
114
114
|
params_can = find_child PARAMS
|
115
115
|
return nil unless params_can
|
116
116
|
|
117
|
+
# First set URL route params if there are any.
|
118
|
+
if @request&.request_params&.route_params
|
119
|
+
@request.request_params.route_params.each_with_index do |route_p,i|
|
120
|
+
o = params_can.children[i]
|
121
|
+
o.set_value( route_p ) if o && o.name != ID
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
117
125
|
if @request
|
118
|
-
url_params = @request.query_params
|
126
|
+
url_params = @request.request_params.query_params
|
119
127
|
url_params.each do |k,v|
|
120
128
|
o = params_can.find_child k
|
121
129
|
o.set_value( v ) if o
|
122
130
|
end
|
123
131
|
|
124
|
-
@request.body_params.each do |k,v|
|
132
|
+
@request.request_params.body_params.each do |k,v|
|
125
133
|
o = params_can.find_child k
|
126
134
|
o.set_value( v ) if o
|
127
135
|
end
|
@@ -316,8 +324,8 @@ module Gloo
|
|
316
324
|
# Set the ID parameter if there is one.
|
317
325
|
#
|
318
326
|
def set_id
|
319
|
-
return unless @request.id
|
320
|
-
@engine.log.info "Setting ID: #{@request.id}"
|
327
|
+
return unless @request.request_params.id
|
328
|
+
@engine.log.info "Setting ID: #{@request.request_params.id}"
|
321
329
|
|
322
330
|
params_can = find_child PARAMS
|
323
331
|
return nil unless params_can
|
@@ -325,7 +333,7 @@ module Gloo
|
|
325
333
|
id_obj = params_can.find_child( ID )
|
326
334
|
return unless id_obj
|
327
335
|
|
328
|
-
id_obj.set_value( @request.id )
|
336
|
+
id_obj.set_value( @request.request_params.id )
|
329
337
|
end
|
330
338
|
|
331
339
|
#
|
@@ -336,6 +344,8 @@ module Gloo
|
|
336
344
|
#
|
337
345
|
def render request=nil
|
338
346
|
@request = request
|
347
|
+
|
348
|
+
# TODO : refactor this
|
339
349
|
set_id if @request
|
340
350
|
|
341
351
|
# Run the on prerender script
|
@@ -354,7 +364,7 @@ module Gloo
|
|
354
364
|
elsif is_text?
|
355
365
|
contents = render_text params
|
356
366
|
else
|
357
|
-
@engine.
|
367
|
+
@engine.err "Unknown content type: #{content_type}"
|
358
368
|
return nil
|
359
369
|
end
|
360
370
|
|
@@ -50,6 +50,7 @@ module Gloo
|
|
50
50
|
CODE = 'code'.freeze
|
51
51
|
ELAPSED = 'elapsed'.freeze
|
52
52
|
DB = 'db'.freeze
|
53
|
+
PAGE = 'page'.freeze
|
53
54
|
|
54
55
|
# Container with pages in the web app.
|
55
56
|
PAGES = 'pages'.freeze
|
@@ -73,7 +74,8 @@ module Gloo
|
|
73
74
|
# If the redirect is set, then use that page instead
|
74
75
|
# of the one requested.
|
75
76
|
#
|
76
|
-
attr_accessor :redirect, :
|
77
|
+
attr_accessor :redirect, :redirect_hard
|
78
|
+
attr_accessor :router, :asset, :embedded_renderer
|
77
79
|
attr_accessor :session
|
78
80
|
|
79
81
|
#
|
@@ -291,7 +293,7 @@ module Gloo
|
|
291
293
|
child_obj = session_container.find_child( key )
|
292
294
|
unless child_obj
|
293
295
|
fac = @engine.factory
|
294
|
-
child_obj = fac.create_string key, value,
|
296
|
+
child_obj = fac.create_string key, value, session_container
|
295
297
|
end
|
296
298
|
child_obj.value = value
|
297
299
|
end
|
@@ -426,7 +428,7 @@ module Gloo
|
|
426
428
|
@engine.stop_running_app
|
427
429
|
# The running app will call the stop function (below)
|
428
430
|
else
|
429
|
-
@engine.
|
431
|
+
@engine.err SERVER_NOT_RUNNING
|
430
432
|
end
|
431
433
|
end
|
432
434
|
|
@@ -437,7 +439,7 @@ module Gloo
|
|
437
439
|
if @router
|
438
440
|
@router.show_routes
|
439
441
|
else
|
440
|
-
@engine.
|
442
|
+
@engine.err SERVER_NOT_RUNNING
|
441
443
|
end
|
442
444
|
end
|
443
445
|
|
@@ -558,15 +560,29 @@ module Gloo
|
|
558
560
|
# This is done after the page is rendered and before
|
559
561
|
# the on_response event is fired.
|
560
562
|
#
|
561
|
-
def set_response_data( request, response )
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
563
|
+
def set_response_data( request, response, page_obj=nil )
|
564
|
+
begin
|
565
|
+
data = find_child RESPONSE_DATA
|
566
|
+
return unless data
|
567
|
+
data = Gloo::Objs::Alias.resolve_alias( @engine, data )
|
568
|
+
|
569
|
+
data.find_child( ELAPSED )&.set_value( request.elapsed )
|
570
|
+
data.find_child( DB )&.set_value( request.db )
|
571
|
+
|
572
|
+
if ( response )
|
573
|
+
data.find_child( TYPE )&.set_value( response.type )
|
574
|
+
data.find_child( CODE )&.set_value( response.code )
|
575
|
+
else
|
576
|
+
data.find_child( TYPE )&.set_value( '' )
|
577
|
+
data.find_child( CODE )&.set_value( '' )
|
578
|
+
end
|
579
|
+
|
580
|
+
if page_obj
|
581
|
+
data.find_child( PAGE )&.set_value( page_obj.pn )
|
582
|
+
end
|
583
|
+
rescue => e
|
584
|
+
@engine.log_exception e
|
585
|
+
end
|
570
586
|
end
|
571
587
|
|
572
588
|
|
@@ -35,7 +35,7 @@ module Gloo
|
|
35
35
|
#
|
36
36
|
def load
|
37
37
|
unless @mech.exist?( @pn )
|
38
|
-
@engine.
|
38
|
+
@engine.err "File '#{@pn}' does not exist."
|
39
39
|
return
|
40
40
|
end
|
41
41
|
|
@@ -154,7 +154,7 @@ module Gloo
|
|
154
154
|
params = { name: name, type: type, value: value, parent: @parent }
|
155
155
|
@last = @engine.factory.create( params )
|
156
156
|
|
157
|
-
if value
|
157
|
+
if value&.empty? && @last&.multiline_value?
|
158
158
|
@multi_indent = 0
|
159
159
|
@in_multiline = true
|
160
160
|
puts "*** Start multiline. multi_indent: #{@multi_indent}" if @debug
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# Alternate version of the Tell verb.
|
5
|
+
# Reads better to check object conditions.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Gloo
|
9
|
+
module Verbs
|
10
|
+
class Check < Gloo::Core::Verb
|
11
|
+
|
12
|
+
KEYWORD = 'check'.freeze
|
13
|
+
KEYWORD_SHORT = '<-'.freeze
|
14
|
+
FOR = 'for'.freeze
|
15
|
+
UNKNOWN_MSG_ERR = 'Missing message!'.freeze
|
16
|
+
|
17
|
+
#
|
18
|
+
# Run the verb.
|
19
|
+
#
|
20
|
+
def run
|
21
|
+
msg = @tokens.after_token( FOR )
|
22
|
+
|
23
|
+
unless msg
|
24
|
+
@engine.err( UNKNOWN_MSG_ERR )
|
25
|
+
return
|
26
|
+
end
|
27
|
+
|
28
|
+
Gloo::Exec::Dispatch.send_message(
|
29
|
+
@engine, msg, @tokens.second, @params )
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Get the Verb's keyword.
|
34
|
+
#
|
35
|
+
def self.keyword
|
36
|
+
return KEYWORD
|
37
|
+
end
|
38
|
+
|
39
|
+
#
|
40
|
+
# Get the Verb's keyword shortcut.
|
41
|
+
#
|
42
|
+
def self.keyword_shortcut
|
43
|
+
return KEYWORD_SHORT
|
44
|
+
end
|
45
|
+
|
46
|
+
# ---------------------------------------------------------------------
|
47
|
+
# Private functions
|
48
|
+
# ---------------------------------------------------------------------
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/gloo/verbs/redirect.rb
CHANGED
@@ -13,6 +13,7 @@ module Gloo
|
|
13
13
|
KEYWORD_SHORT = 'go'.freeze
|
14
14
|
|
15
15
|
RUN_MESSAGE = 'run'.freeze
|
16
|
+
KEYWORD_HARD = 'hard'.freeze
|
16
17
|
|
17
18
|
MISSING_EXPR_ERR = 'Missing Expression!'.freeze
|
18
19
|
APP_NOT_RUNING_ERR = 'The application is not running!'.freeze
|
@@ -27,8 +28,12 @@ module Gloo
|
|
27
28
|
return
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
if is_hard_redirect?
|
32
|
+
redirect_hard
|
33
|
+
else
|
34
|
+
determine_target
|
35
|
+
redirect_to_target
|
36
|
+
end
|
32
37
|
end
|
33
38
|
|
34
39
|
#
|
@@ -51,6 +56,32 @@ module Gloo
|
|
51
56
|
|
52
57
|
private
|
53
58
|
|
59
|
+
#
|
60
|
+
# Is this a hard redirect?
|
61
|
+
# A hard redirect returns the new URL to the client.
|
62
|
+
#
|
63
|
+
def is_hard_redirect?
|
64
|
+
return false unless @params&.token_count&.positive?
|
65
|
+
|
66
|
+
param_val = @params.tokens.first
|
67
|
+
return ( param_val.downcase == KEYWORD_HARD )
|
68
|
+
end
|
69
|
+
|
70
|
+
#
|
71
|
+
# Redirect to the target using a hard redirect.
|
72
|
+
#
|
73
|
+
def redirect_hard
|
74
|
+
expr = Gloo::Expr::Expression.new( @engine, @tokens.params )
|
75
|
+
to_site = expr.evaluate
|
76
|
+
|
77
|
+
if @engine.app_running?
|
78
|
+
@engine.exec_env.running_script.break_out
|
79
|
+
@engine.running_app.obj.redirect_hard = to_site
|
80
|
+
else
|
81
|
+
@engine.err APP_NOT_RUNING_ERR
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
54
85
|
#
|
55
86
|
# Send the control to the redirect target.
|
56
87
|
# This could be a page or a script.
|
@@ -83,6 +114,7 @@ module Gloo
|
|
83
114
|
#
|
84
115
|
def redirect_to_page
|
85
116
|
if @engine.app_running?
|
117
|
+
@engine.exec_env.running_script.break_out
|
86
118
|
@engine.running_app.obj.redirect = @target_obj
|
87
119
|
else
|
88
120
|
@engine.err APP_NOT_RUNING_ERR
|
data/lib/gloo/verbs/tell.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
2
|
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# Send a message to an object.
|
5
|
+
# Tell the object to do some known action.
|
6
|
+
# Also see the Check verb.
|
5
7
|
#
|
6
8
|
|
7
9
|
module Gloo
|
@@ -11,18 +13,21 @@ module Gloo
|
|
11
13
|
KEYWORD = 'tell'.freeze
|
12
14
|
KEYWORD_SHORT = '->'.freeze
|
13
15
|
TO = 'to'.freeze
|
14
|
-
OBJ_NOT_FOUND_ERR = 'Object was not found: '.freeze
|
15
16
|
UNKNOWN_MSG_ERR = 'Missing message!'.freeze
|
16
17
|
|
17
18
|
#
|
18
19
|
# Run the verb.
|
19
20
|
#
|
20
21
|
def run
|
21
|
-
|
22
|
-
return unless @msg
|
22
|
+
msg = @tokens.after_token( TO )
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
unless msg
|
25
|
+
@engine.err( UNKNOWN_MSG_ERR )
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
Gloo::Exec::Dispatch.send_message(
|
30
|
+
@engine, msg, @tokens.second, @params )
|
26
31
|
end
|
27
32
|
|
28
33
|
#
|
@@ -45,36 +50,6 @@ module Gloo
|
|
45
50
|
|
46
51
|
private
|
47
52
|
|
48
|
-
#
|
49
|
-
# Lookup the message to send.
|
50
|
-
#
|
51
|
-
def setup_msg
|
52
|
-
@msg = @tokens.after_token( TO )
|
53
|
-
|
54
|
-
@engine.err( UNKNOWN_MSG_ERR ) unless @msg
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# Setup the target of the message.
|
59
|
-
#
|
60
|
-
def setup_target
|
61
|
-
@obj_name = @tokens.second
|
62
|
-
pn = Gloo::Core::Pn.new( @engine, @obj_name )
|
63
|
-
@target_obj = pn.resolve
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# Dispatch the message to the target object.
|
68
|
-
#
|
69
|
-
def dispatch_msg
|
70
|
-
if @target_obj
|
71
|
-
Gloo::Exec::Dispatch.message(
|
72
|
-
@engine, @msg, @target_obj, @params )
|
73
|
-
else
|
74
|
-
@engine.err "#{OBJ_NOT_FOUND_ERR} #{@obj_name}"
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
53
|
end
|
79
54
|
end
|
80
55
|
end
|
data/lib/gloo/web_svr/handler.rb
CHANGED
@@ -35,21 +35,28 @@ module Gloo
|
|
35
35
|
#
|
36
36
|
def handle request
|
37
37
|
@request = request
|
38
|
+
page_obj = nil
|
39
|
+
route_params = nil
|
38
40
|
|
39
|
-
page, id = @server_obj.router.page_for_route( @request.path, @request.method )
|
41
|
+
page, id, route_params = @server_obj.router.page_for_route( @request.path, @request.method )
|
40
42
|
@engine.log.debug "Found Page: #{page&.name}" if page
|
41
|
-
|
43
|
+
|
44
|
+
request.request_params.id = id
|
45
|
+
request.request_params.route_params = route_params
|
46
|
+
request.request_params.log_id_keys
|
47
|
+
|
42
48
|
if page
|
43
49
|
if page.is_a? Gloo::Objs::FileHandle
|
44
50
|
result = handle_file page
|
45
51
|
else
|
46
52
|
result = handle_page page
|
53
|
+
page_obj = page
|
47
54
|
end
|
48
55
|
else
|
49
56
|
result = server_error_result
|
50
57
|
end
|
51
58
|
|
52
|
-
return result
|
59
|
+
return result, page_obj
|
53
60
|
end
|
54
61
|
|
55
62
|
#
|
@@ -58,7 +65,10 @@ module Gloo
|
|
58
65
|
#
|
59
66
|
def handle_page page
|
60
67
|
result = page.render @request
|
61
|
-
if
|
68
|
+
if redirect_hard_set?
|
69
|
+
result = server_redirect_result
|
70
|
+
@engine.running_app.obj.redirect_hard = nil
|
71
|
+
elsif redirect_set?
|
62
72
|
page = @engine.running_app.obj.redirect
|
63
73
|
@log.debug "Redirecting to: #{page.pn}"
|
64
74
|
@engine.running_app.obj.redirect = nil
|
@@ -108,7 +118,7 @@ module Gloo
|
|
108
118
|
|
109
119
|
|
110
120
|
# ---------------------------------------------------------------------
|
111
|
-
# Helper functions
|
121
|
+
# Redirect Helper functions
|
112
122
|
# ---------------------------------------------------------------------
|
113
123
|
|
114
124
|
#
|
@@ -119,6 +129,23 @@ module Gloo
|
|
119
129
|
return @engine.running_app.obj.redirect
|
120
130
|
end
|
121
131
|
|
132
|
+
#
|
133
|
+
# Is there a redirect page set in the running app?
|
134
|
+
#
|
135
|
+
def redirect_hard_set?
|
136
|
+
return false unless @engine.app_running?
|
137
|
+
return @engine.running_app.obj.redirect_hard
|
138
|
+
end
|
139
|
+
|
140
|
+
#
|
141
|
+
# Return a redirect result.
|
142
|
+
#
|
143
|
+
def server_redirect_result
|
144
|
+
target = @engine.running_app.obj.redirect_hard
|
145
|
+
|
146
|
+
return Gloo::WebSvr::Response.redirect_response( @engine, target )
|
147
|
+
end
|
148
|
+
|
122
149
|
end
|
123
150
|
end
|
124
151
|
end
|
data/lib/gloo/web_svr/request.rb
CHANGED
@@ -23,9 +23,9 @@ module Gloo
|
|
23
23
|
HTTP_HOST = 'HTTP_HOST'.freeze
|
24
24
|
QUERY_STRING = 'QUERY_STRING'.freeze
|
25
25
|
|
26
|
-
attr_reader :method, :host, :path, :
|
26
|
+
attr_reader :method, :host, :path, :ip, :query
|
27
27
|
attr_reader :db, :elapsed
|
28
|
-
attr_accessor :
|
28
|
+
attr_accessor :request_params
|
29
29
|
|
30
30
|
|
31
31
|
# ---------------------------------------------------------------------
|
@@ -38,6 +38,7 @@ module Gloo
|
|
38
38
|
def initialize( engine, handler, env = nil )
|
39
39
|
@engine = engine
|
40
40
|
@log = @engine.log
|
41
|
+
@request_params = RequestParams.new( @log )
|
41
42
|
|
42
43
|
@handler = handler
|
43
44
|
|
@@ -60,11 +61,11 @@ module Gloo
|
|
60
61
|
@handler.server_obj.set_request_data self
|
61
62
|
@handler.server_obj.run_on_request
|
62
63
|
|
63
|
-
result = @handler.handle self
|
64
|
+
result, page_obj = @handler.handle self
|
64
65
|
finish_timer
|
65
66
|
|
66
67
|
# Run the on_response script if there is one.
|
67
|
-
@handler.server_obj.set_response_data self, result
|
68
|
+
@handler.server_obj.set_response_data( self, result, page_obj )
|
68
69
|
@handler.server_obj.run_on_response
|
69
70
|
|
70
71
|
return result
|
@@ -85,18 +86,13 @@ module Gloo
|
|
85
86
|
@path = req.path
|
86
87
|
@host = req.host_with_port
|
87
88
|
@query = req.query_string
|
88
|
-
@ip = req.ip
|
89
|
-
|
90
|
-
# @method = @env[ REQUEST_METHOD ]
|
91
|
-
# @path = @env[ REQUEST_PATH ]
|
92
|
-
# @host = @env[ HTTP_HOST ]
|
93
|
-
# @query = @env[ QUERY_STRING ]
|
94
89
|
|
90
|
+
@request_params.init_query_params( @query )
|
91
|
+
@ip = req.ip
|
95
92
|
@handler.server_obj.session.set_session_data_for_request( @env )
|
96
93
|
|
97
|
-
@
|
98
|
-
@
|
99
|
-
check_body_method
|
94
|
+
@request_params.init_body_params( @env[ 'rack.input' ].read )
|
95
|
+
@method = @request_params.get_body_method_override @method
|
100
96
|
end
|
101
97
|
|
102
98
|
|
@@ -127,38 +123,13 @@ module Gloo
|
|
127
123
|
# Helper functions
|
128
124
|
# ---------------------------------------------------------------------
|
129
125
|
|
130
|
-
#
|
131
|
-
# Check the body to see if there is a PATCH or a PUT in
|
132
|
-
# the method override.
|
133
|
-
#
|
134
|
-
def check_body_method
|
135
|
-
if @body[ '_method' ]
|
136
|
-
@method = @body[ '_method' ].upcase
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
#
|
141
|
-
# Get the hash of query parameters.
|
142
|
-
#
|
143
|
-
def query_params
|
144
|
-
return {} unless @query
|
145
|
-
return Rack::Utils.parse_query( @query )
|
146
|
-
end
|
147
|
-
|
148
|
-
#
|
149
|
-
# Get the hash of body parameters.
|
150
|
-
#
|
151
|
-
def body_params
|
152
|
-
return @body ? @body : {}
|
153
|
-
end
|
154
|
-
|
155
126
|
#
|
156
127
|
# Write the request information to the log.
|
157
128
|
#
|
158
129
|
def log
|
159
130
|
@log.info "#{@method} #{@host}#{@path}"
|
160
|
-
|
161
|
-
@
|
131
|
+
|
132
|
+
@request_params.log_params
|
162
133
|
end
|
163
134
|
|
164
135
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
+
# Copyright:: Copyright (c) 2024 Eric Crane. All rights reserved.
|
3
|
+
#
|
4
|
+
# A Parameters associated with a request.
|
5
|
+
#
|
6
|
+
# Kinds of Params
|
7
|
+
# Id - The entity id
|
8
|
+
# Key - URL parameter key
|
9
|
+
# URL Params - Parameters in the URL
|
10
|
+
# Body Params - Data from the body of the request
|
11
|
+
#
|
12
|
+
|
13
|
+
module Gloo
|
14
|
+
module WebSvr
|
15
|
+
class RequestParams
|
16
|
+
|
17
|
+
attr_accessor :id, :route_params
|
18
|
+
attr_reader :query_params, :body_params
|
19
|
+
|
20
|
+
# ---------------------------------------------------------------------
|
21
|
+
# Initialization
|
22
|
+
# ---------------------------------------------------------------------
|
23
|
+
|
24
|
+
#
|
25
|
+
# Set up the web server.
|
26
|
+
#
|
27
|
+
def initialize( log )
|
28
|
+
@log = log
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# ---------------------------------------------------------------------
|
33
|
+
# Value Detection
|
34
|
+
# ---------------------------------------------------------------------
|
35
|
+
|
36
|
+
#
|
37
|
+
# Detect the parameters from query string.
|
38
|
+
#
|
39
|
+
def init_query_params query_string
|
40
|
+
if query_string
|
41
|
+
@query_params = Rack::Utils.parse_query( query_string )
|
42
|
+
else
|
43
|
+
@query_params = {}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Detect the parameters from the body of the request.
|
49
|
+
#
|
50
|
+
def init_body_params body
|
51
|
+
if body
|
52
|
+
@body_params = Rack::Utils.parse_query body
|
53
|
+
else
|
54
|
+
@body_params = {}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# ---------------------------------------------------------------------
|
60
|
+
# Helper functions
|
61
|
+
# ---------------------------------------------------------------------
|
62
|
+
|
63
|
+
#
|
64
|
+
# Check the body to see if there is a PATCH or a PUT in
|
65
|
+
# the method override.
|
66
|
+
#
|
67
|
+
def get_body_method_override orig_method
|
68
|
+
if @body_params[ '_method' ]
|
69
|
+
return @body_params[ '_method' ].upcase
|
70
|
+
end
|
71
|
+
return orig_method
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Write the querey and body params to the log.
|
76
|
+
#
|
77
|
+
def log_params
|
78
|
+
return unless @log
|
79
|
+
|
80
|
+
if @query_params && ! @query_params.empty?
|
81
|
+
@log.info "--- Query Parameters: #{@query_params}"
|
82
|
+
end
|
83
|
+
|
84
|
+
if @body_params && ! @body_params.empty?
|
85
|
+
@log.info "--- Body Parameters: #{@body_params}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Write the id and route params to the log.
|
91
|
+
#
|
92
|
+
def log_id_keys
|
93
|
+
return unless @log
|
94
|
+
|
95
|
+
@log.info "--- ID Parameter: #{@id}" if @id
|
96
|
+
|
97
|
+
if @route_params && ! @route_params.empty?
|
98
|
+
@log.info "--- Route Parameters: #{@route_params}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -18,6 +18,7 @@ module Gloo
|
|
18
18
|
HTML_TYPE = 'text/html'.freeze
|
19
19
|
|
20
20
|
attr_reader :code, :type, :data
|
21
|
+
attr_accessor :location
|
21
22
|
|
22
23
|
|
23
24
|
# ---------------------------------------------------------------------
|
@@ -37,6 +38,7 @@ module Gloo
|
|
37
38
|
@code = code
|
38
39
|
@type = type
|
39
40
|
@data = data
|
41
|
+
@location = nil
|
40
42
|
end
|
41
43
|
|
42
44
|
|
@@ -71,6 +73,25 @@ module Gloo
|
|
71
73
|
return Gloo::WebSvr::Response.new( engine, code, HTML_TYPE, data )
|
72
74
|
end
|
73
75
|
|
76
|
+
#
|
77
|
+
# Helper to create a redirect response.
|
78
|
+
#
|
79
|
+
def self.redirect_response( engine, target )
|
80
|
+
code = Gloo::WebSvr::ResponseCode::FOUND
|
81
|
+
data = <<~TEXT
|
82
|
+
<head>
|
83
|
+
<html>
|
84
|
+
<body><a href="#{target}">target is here</a></body>
|
85
|
+
</html>
|
86
|
+
</head>
|
87
|
+
TEXT
|
88
|
+
|
89
|
+
response = Gloo::WebSvr::Response.new( engine, code, HTML_TYPE, data )
|
90
|
+
response.location = target
|
91
|
+
|
92
|
+
return response
|
93
|
+
end
|
94
|
+
|
74
95
|
|
75
96
|
# ---------------------------------------------------------------------
|
76
97
|
# Data Functions
|
@@ -97,6 +118,10 @@ module Gloo
|
|
97
118
|
|
98
119
|
headers = { CONTENT_TYPE => @type }
|
99
120
|
|
121
|
+
if @location
|
122
|
+
headers[ 'Location' ] = @location
|
123
|
+
end
|
124
|
+
|
100
125
|
session = @engine&.running_app&.obj&.session
|
101
126
|
headers = session.add_session_for_response( headers ) if session
|
102
127
|
|