Class: CGI

Inherits:
Object
  • Object
show all
Defined in:
lib/support/cgi.rb

Constant Summary collapse

HTTP_PORT =
80
HTTPS_PORT =
443

Instance Method Summary collapse

Instance Method Details

#full_uri_for(fragment) ⇒ Object

Returns a full uri for a given uri fragment. full_uri_for ‘foo.cgi’ => ‘localhost/dir/foo.cgi’ full_uri_for ‘/images/’ => ‘localhost/images/’



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/support/cgi.rb', line 8

def full_uri_for(fragment)
  case fragment
  when /^http:\/\//
    # The fragment is a complete URI
    fragment
  when /^\//
    # The fragment is relative to the root of this host
    host_uri + fragment
  else
    # The fragment is relative to this directory
    relative_uri + fragment
  end
end

#host_uriObject

Try to guess the uri for the host alone (host/)



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/support/cgi.rb', line 23

def host_uri
  uri = ''
  case server_port
  when HTTP_PORT
    uri << 'http://' + server_name
  when HTTPS_PORT
    uri << 'https://' + server_name
  else
    uri << 'https://' + server_name + ':' + server_port
  end
  uri << '/'
end

#relative_uriObject

Try to guess the relative path for this request. (host/directory/)



37
38
39
# File 'lib/support/cgi.rb', line 37

def relative_uri
  uri.sub(/[^\/]*$/, '')
end

#uriObject

Try to guess the full uri for this script (host/directory/script.cgi)



42
43
44
# File 'lib/support/cgi.rb', line 42

def uri
  host_uri.chop + script_name
end