Class: Refraction::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/refraction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



6
7
8
# File 'lib/refraction.rb', line 6

def action
  @action
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/refraction.rb', line 6

def message
  @message
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/refraction.rb', line 6

def status
  @status
end

Instance Method Details

#found!(options) ⇒ Object



39
40
41
42
43
44
# File 'lib/refraction.rb', line 39

def found!(options)
  @action = :found
  @status = 302
  set(options)
  @message = "moved to #{@uri}"
end

#hostObject



67
# File 'lib/refraction.rb', line 67

def host;         @re_host   || super; end

#host_with_portObject



76
77
78
# File 'lib/refraction.rb', line 76

def host_with_port
  port.nil? || port == DEFAULT_PORTS[scheme] ? host : "#{host}:#{port}"
end

#http_hostObject



80
81
82
# File 'lib/refraction.rb', line 80

def http_host
  port ? "#{host}:#{port}" : host
end

#locationObject



61
62
63
# File 'lib/refraction.rb', line 61

def location
  @re_location || url
end

#methodObject

backward compatibility: support URI::HTTP component names



9
# File 'lib/refraction.rb', line 9

def method; request_method; end

#pathObject



68
# File 'lib/refraction.rb', line 68

def path;         @re_path   || super; end

#permanent!(options) ⇒ Object



32
33
34
35
36
37
# File 'lib/refraction.rb', line 32

def permanent!(options)
  @action = :permanent
  @status = 301
  set(options)
  @message = "moved to #{@uri}"
end

#portObject

changing the scheme or host means use default port instead of port in original request



72
73
74
# File 'lib/refraction.rb', line 72

def port
  @re_port || ((@re_scheme || @re_host) && DEFAULT_PORTS[scheme]) || super
end

#queryObject



10
# File 'lib/refraction.rb', line 10

def query;  query_string;   end

#query_stringObject



69
# File 'lib/refraction.rb', line 69

def query_string; @re_query  || super; end

#respond!(status, headers, content) ⇒ Object



46
47
48
49
50
51
# File 'lib/refraction.rb', line 46

def respond!(status, headers, content)
  @action = :respond
  @status = status
  @headers = headers
  @message = content
end

#responseObject

response



55
56
57
58
59
# File 'lib/refraction.rb', line 55

def response
  headers = @headers || { 'Location' => location, 'Content-Type' => 'text/plain' }
  headers['Content-Length'] = message.length.to_s
  [status, headers, [message]]
end

#rewrite!(options) ⇒ Object



27
28
29
30
# File 'lib/refraction.rb', line 27

def rewrite!(options)
  @action = :rewrite
  set(options)
end

#schemeObject

use original request’s values when not set explicitly



66
# File 'lib/refraction.rb', line 66

def scheme;       @re_scheme || super; end

#set(options) ⇒ Object

actions



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/refraction.rb', line 14

def set(options)
  if options.is_a?(String)
    @re_location = options
  else
    @re_scheme = options[:protocol] if options[:protocol] # :protocol is alias for :scheme
    @re_scheme = options[:scheme]   if options[:scheme]
    @re_host   = options[:host]     if options[:host]
    @re_port   = options[:port]     if options[:port]
    @re_path   = options[:path]     if options[:path]
    @re_query  = options[:query]    if options[:query]
  end
end