module Rack::TestApp::Util

Constants

Public Instance Methods

guess_content_type(filename, default='application/octet-stream') click to toggle source
# File lib/rack/test_app.rb, line 111
def guess_content_type(filename, default='application/octet-stream')
  #; [!xw0js] returns content type guessed from filename.
  #; [!dku5c] returns 'application/octet-stream' when failed to guess content type.
  ext = ::File.extname(filename)
  return Rack::Mime.mime_type(ext, default)
end
percent_decode(str) click to toggle source
# File lib/rack/test_app.rb, line 34
def percent_decode(str)
  #; [!kl9sk] decodes percent encoded string.
  return URI.decode_www_form_component(str)
end
percent_encode(str) click to toggle source
# File lib/rack/test_app.rb, line 29
def percent_encode(str)
  #; [!a96jo] encodes string into percent encoding format.
  return URI.encode_www_form_component(str)
end
randstr_b64() click to toggle source
# File lib/rack/test_app.rb, line 102
def randstr_b64()
  #; [!yq0gv] returns random string, encoded with urlsafe base64.
  ## Don't use SecureRandom; entropy of /dev/random or /dev/urandom
  ## should be left for more secure-sensitive purpose.
  s = "#{rand()}#{rand()}#{rand()}#{Time.now.to_f}"
  binary = ::Digest::SHA1.digest(s)
  return [binary].pack('m').chomp("=\n").tr('+/', '-_')
end