Module: Roda::RodaPlugins::HmacPaths::RequestMethods

Defined in:
lib/roda/plugins/hmac_paths.rb

Instance Method Summary collapse

Instance Method Details

#hmac_path(opts = OPTS, &block) ⇒ Object

Looks at the first segment of the remaining path, and if it contains a valid HMAC for the rest of the path considering the flags in the second segment and the given options, the block matches and is yielded to, and the result of the block is returned. Otherwise, the block does not matches and routing continues after the call.



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/roda/plugins/hmac_paths.rb', line 214

def hmac_path(opts=OPTS, &block)
  orig_path = remaining_path
  mpath = matched_path

  on String do ||
    rpath = remaining_path

    if .bytesize == 64
      on String do |flags|
        if flags.bytesize >= 1
          if flags.include?('m')
            rpath = "#{env['REQUEST_METHOD'].to_s.upcase}:#{rpath}"
          end

          if flags.include?('p')
            rpath = "#{rpath}?#{env["QUERY_STRING"]}"
          end

          if hmac_path_valid?(mpath, rpath, )
            always(&block)
          end
        end

        # Return from method without matching
        @remaining_path = orig_path
        return
      end
    end

    # Return from method without matching
    @remaining_path = orig_path
    return
  end
end