Class: Gloo::WebSvr::RequestParams
- Inherits:
-
Object
- Object
- Gloo::WebSvr::RequestParams
- Defined in:
- lib/gloo/web_svr/request_params.rb
Instance Attribute Summary collapse
-
#body_binary ⇒ Object
readonly
Returns the value of attribute body_binary.
-
#body_params ⇒ Object
readonly
Returns the value of attribute body_params.
-
#id ⇒ Object
Returns the value of attribute id.
-
#query_params ⇒ Object
readonly
Returns the value of attribute query_params.
-
#route_params ⇒ Object
Returns the value of attribute route_params.
Instance Method Summary collapse
-
#check_authenticity_token(engine) ⇒ Object
Check the authenticity token if it is present.
-
#get_body_method_override(orig_method) ⇒ Object
Check the body to see if there is a PATCH or a PUT in the method override.
-
#init_body_params(body) ⇒ Object
Detect the parameters from the body of the request.
-
#init_multipart(body) ⇒ Object
Set the body to a binary file.
-
#init_query_params(query_string) ⇒ Object
Detect the parameters from query string.
-
#initialize(log) ⇒ RequestParams
constructor
Set up the web server.
-
#log_id_keys ⇒ Object
Write the id and route params to the log.
-
#log_params ⇒ Object
Write the querey and body params to the log.
Constructor Details
#initialize(log) ⇒ RequestParams
Set up the web server.
27 28 29 |
# File 'lib/gloo/web_svr/request_params.rb', line 27 def initialize( log ) @log = log end |
Instance Attribute Details
#body_binary ⇒ Object (readonly)
Returns the value of attribute body_binary.
18 19 20 |
# File 'lib/gloo/web_svr/request_params.rb', line 18 def body_binary @body_binary end |
#body_params ⇒ Object (readonly)
Returns the value of attribute body_params.
18 19 20 |
# File 'lib/gloo/web_svr/request_params.rb', line 18 def body_params @body_params end |
#id ⇒ Object
Returns the value of attribute id.
17 18 19 |
# File 'lib/gloo/web_svr/request_params.rb', line 17 def id @id end |
#query_params ⇒ Object (readonly)
Returns the value of attribute query_params.
18 19 20 |
# File 'lib/gloo/web_svr/request_params.rb', line 18 def query_params @query_params end |
#route_params ⇒ Object
Returns the value of attribute route_params.
17 18 19 |
# File 'lib/gloo/web_svr/request_params.rb', line 17 def route_params @route_params end |
Instance Method Details
#check_authenticity_token(engine) ⇒ Object
Check the authenticity token if it is present. Returns true if it is present and valid, and also if it is not present. Returns false if it is present but not valid.
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/gloo/web_svr/request_params.rb', line 115 def check_authenticity_token engine auth_token = @query_params[ Gloo::Objs::CsrfToken::AUTHENTICITY_TOKEN ] if auth_token session_id = engine.running_app.obj&.session&.get_session_id return false unless session_id return Gloo::Objs::CsrfToken.valid_csrf_token?( session_id, auth_token ) end return true end |
#get_body_method_override(orig_method) ⇒ Object
Check the body to see if there is a PATCH or a PUT in the method override.
136 137 138 139 140 141 |
# File 'lib/gloo/web_svr/request_params.rb', line 136 def get_body_method_override orig_method if @body_params[ '_method' ] return @body_params[ '_method' ].upcase end return orig_method end |
#init_body_params(body) ⇒ Object
Detect the parameters from the body of the request.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gloo/web_svr/request_params.rb', line 50 def init_body_params body if body && body.length > 0 # if body is binary, then it is not a query string begin @body_params = Rack::Utils.parse_query body rescue => exception init_multipart body end else @body_params = {} end end |
#init_multipart(body) ⇒ Object
Set the body to a binary file.
TODO: find a lib or method to handle this. This is very rough and will need to be fixed.
69 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 |
# File 'lib/gloo/web_svr/request_params.rb', line 69 def init_multipart body # puts "*********** first lines: *********** " # body.lines[0..3].each { |line| puts line } # puts "*********** last lines: *********** " # body.lines.last(5).each { |line| puts line } # puts "************************************" # boundary = body.lines.first # puts "boundary: #{boundary}" header = body.lines[1..3].join # puts "header: #{header}" = body.lines.last(5).join # puts "footer: #{footer}" binary_data = body.lines[4..-6].join # puts "binary_data length: #{binary_data.length}" # puts "binary first line: #{binary_data.lines.first}" # puts "binary last line: #{binary_data.lines.last}" i = header.lines.first.index( 'filename=' ) filename = header.lines.first[ i+10..-4 ] content_type = header.lines.second[14..-3] # puts "filename: #{filename}" # puts "content_type: #{content_type}" @body_binary = body @body_params = {} @body_params[ 'content_type' ] = content_type @body_params[ 'file_name' ] = filename @body_params[ 'file_size' ] = binary_data.length @body_params[ 'file_data' ] = binary_data end |
#init_query_params(query_string) ⇒ Object
Detect the parameters from query string.
39 40 41 42 43 44 45 |
# File 'lib/gloo/web_svr/request_params.rb', line 39 def init_query_params query_string if query_string @query_params = Rack::Utils.parse_query( query_string ) else @query_params = {} end end |
#log_id_keys ⇒ Object
Write the id and route params to the log.
169 170 171 172 173 174 175 176 177 |
# File 'lib/gloo/web_svr/request_params.rb', line 169 def log_id_keys return unless @log @log.info "--- ID Parameter: #{@id}" if @id if @route_params && ! @route_params.empty? @log.info "--- Route Parameters: #{@route_params}" end end |
#log_params ⇒ Object
Write the querey and body params to the log.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gloo/web_svr/request_params.rb', line 146 def log_params return unless @log if @query_params && ! @query_params.empty? @log.info "--- Query Parameters: #{@query_params}" end if @body_params && ! @body_params.empty? if @body_params[ 'file_data' ] # exclude the file data from the params shown params = @body_params.dup params.delete( 'file_data' ) params[ 'file_data' ] = '...' @log.info "--- Body Parameters: #{params}" else @log.info "--- Body Parameters: #{@body_params}" end end end |