Class: CGI
- Inherits:
-
Object
- Object
- CGI
- Defined in:
- lib/cgi.rb
Constant Summary collapse
- HTTP_PORT =
80
- HTTPS_PORT =
443
Instance Method Summary collapse
-
#full_uri_for(fragment) ⇒ Object
Returns a full uri for a given uri fragment.
-
#host_uri ⇒ Object
Try to guess the uri for the host alone (host/).
-
#relative_uri ⇒ Object
Try to guess the relative path for this request.
-
#uri ⇒ Object
Try to guess the full uri for this script (host/directory/script.cgi).
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/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_uri ⇒ Object
Try to guess the uri for the host alone (host/)
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/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_uri ⇒ Object
Try to guess the relative path for this request. (host/directory/)
37 38 39 |
# File 'lib/cgi.rb', line 37 def relative_uri uri.sub(/[^\/]*$/, '') end |
#uri ⇒ Object
Try to guess the full uri for this script (host/directory/script.cgi)
42 43 44 |
# File 'lib/cgi.rb', line 42 def uri host_uri.chop + script_name end |