Module: Fastr::HTTP
- Defined in:
- lib/fastr/http.rb
Class Method Summary collapse
-
.build_query_string(params) ⇒ String
Builds a query string of parameters.
- .method?(env, method) ⇒ Boolean
-
.parse_cookies(env) ⇒ Hash
Parses the HTTP cookie.
-
.parse_query_string(qs) ⇒ Hash
Parses the query string.
Class Method Details
.build_query_string(params) ⇒ String
Builds a query string of parameters.
25 26 27 28 29 30 31 |
# File 'lib/fastr/http.rb', line 25 def self.build_query_string(params) qs = [] params.each do |k,v| qs << "#{k}=#{CGI::escape(v)}" end qs.join('&') end |
.method?(env, method) ⇒ Boolean
33 34 35 36 |
# File 'lib/fastr/http.rb', line 33 def self.method?(env, method) return false if not env['REQUEST_METHOD'] return env['REQUEST_METHOD'].downcase.to_sym == method end |
.parse_cookies(env) ⇒ Hash
Parses the HTTP cookie.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fastr/http.rb', line 42 def self.(env) if env.has_key? "HTTP_COOKIE" = env['HTTP_COOKIE'].split(';') c = {} .each do || info = .strip.split("=") if info.length == 2 c[info[0].strip] = info[1].strip end end c else {} end end |
.parse_query_string(qs) ⇒ Hash
Parses the query string.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fastr/http.rb', line 8 def self.parse_query_string(qs) params = {} return params if not qs CGI::parse(qs).each do |k,v| if v.length == 1 params[k] = v[0] else params[k] = v end end return params end |