source: extensions/gsdl-video/trunk/installed/cmdline/lib/ruby/1.8/uri/http.rb@ 18425

Last change on this file since 18425 was 18425, checked in by davidb, 15 years ago

Video extension to Greenstone

File size: 2.6 KB
Line 
1#
2# = uri/http.rb
3#
4# Author:: Akira Yamada <[email protected]>
5# License:: You can redistribute it and/or modify it under the same term as Ruby.
6# Revision:: $Id: http.rb 11747 2007-02-15 02:41:45Z knu $
7#
8
9require 'uri/generic'
10
11module URI
12
13 #
14 # The syntax of HTTP URIs is defined in RFC1738 section 3.3.
15 #
16 # Note that the Ruby URI library allows HTTP URLs containing usernames and
17 # passwords. This is not legal as per the RFC, but used to be
18 # supported in Internet Explorer 5 and 6, before the MS04-004 security
19 # update. See <URL:http://support.microsoft.com/kb/834489>.
20 #
21 class HTTP < Generic
22 DEFAULT_PORT = 80
23
24 COMPONENT = [
25 :scheme,
26 :userinfo, :host, :port,
27 :path,
28 :query,
29 :fragment
30 ].freeze
31
32 #
33 # == Description
34 #
35 # Create a new URI::HTTP object from components, with syntax checking.
36 #
37 # The components accepted are userinfo, host, port, path, query and
38 # fragment.
39 #
40 # The components should be provided either as an Array, or as a Hash
41 # with keys formed by preceding the component names with a colon.
42 #
43 # If an Array is used, the components must be passed in the order
44 # [userinfo, host, port, path, query, fragment].
45 #
46 # Example:
47 #
48 # newuri = URI::HTTP.build({:host => 'www.example.com',
49 # :path> => '/foo/bar'})
50 #
51 # newuri = URI::HTTP.build([nil, "www.example.com", nil, "/path",
52 # "query", 'fragment'])
53 #
54 # Currently, if passed userinfo components this method generates
55 # invalid HTTP URIs as per RFC 1738.
56 #
57 def self.build(args)
58 tmp = Util::make_components_hash(self, args)
59 return super(tmp)
60 end
61
62 #
63 # == Description
64 #
65 # Create a new URI::HTTP object from generic URI components as per
66 # RFC 2396. No HTTP-specific syntax checking (as per RFC 1738) is
67 # performed.
68 #
69 # Arguments are +scheme+, +userinfo+, +host+, +port+, +registry+, +path+,
70 # +opaque+, +query+ and +fragment+, in that order.
71 #
72 # Example:
73 #
74 # uri = URI::HTTP.new(['http', nil, "www.example.com", nil, "/path",
75 # "query", 'fragment'])
76 #
77 def initialize(*arg)
78 super(*arg)
79 end
80
81 #
82 # == Description
83 #
84 # Returns the full path for an HTTP request, as required by Net::HTTP::Get.
85 #
86 # If the URI contains a query, the full path is URI#path + '?' + URI#query.
87 # Otherwise, the path is simply URI#path.
88 #
89 def request_uri
90 r = path_query
91 if r[0] != ?/
92 r = '/' + r
93 end
94
95 r
96 end
97 end
98
99 @@schemes['HTTP'] = HTTP
100end
Note: See TracBrowser for help on using the repository browser.