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.



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

def action
  @action
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#default_portObject



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

def default_port
  case scheme
  when "http"  ; 80
  when "https" ; 443
  end
end

#found!(options) ⇒ Object



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

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

#hostObject



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

def host;         @re_host   || super; end

#http_hostObject



84
85
86
# File 'lib/refraction.rb', line 84

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

#locationObject



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

def location
  @re_location || url
end

#methodObject

backward compatibility: support URI::HTTP component names



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

def method; request_method; end

#pathObject



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

def path;         @re_path   || super; end

#permanent!(options) ⇒ Object



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

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



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

def port
  @re_port || ((@re_scheme || @re_host) && default_port) || super
end

#queryObject



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

def query;  query_string;   end

#query_stringObject



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

def query_string; @re_query  || super; end

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



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

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

#responseObject

response



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

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

#rewrite!(options) ⇒ Object



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

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

#schemeObject

use original request’s values when not set explicitly



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

def scheme;       @re_scheme || super; end

#set(options) ⇒ Object

actions



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

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