glebtv-httpclient 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +108 -0
  3. data/bin/httpclient +65 -0
  4. data/lib/glebtv-httpclient.rb +1 -0
  5. data/lib/hexdump.rb +50 -0
  6. data/lib/http-access2/cookie.rb +1 -0
  7. data/lib/http-access2/http.rb +1 -0
  8. data/lib/http-access2.rb +55 -0
  9. data/lib/httpclient/auth.rb +899 -0
  10. data/lib/httpclient/cacert.p7s +1912 -0
  11. data/lib/httpclient/connection.rb +88 -0
  12. data/lib/httpclient/cookie.rb +438 -0
  13. data/lib/httpclient/http.rb +1050 -0
  14. data/lib/httpclient/include_client.rb +83 -0
  15. data/lib/httpclient/session.rb +1031 -0
  16. data/lib/httpclient/ssl_config.rb +403 -0
  17. data/lib/httpclient/timeout.rb +140 -0
  18. data/lib/httpclient/util.rb +186 -0
  19. data/lib/httpclient/version.rb +3 -0
  20. data/lib/httpclient.rb +1157 -0
  21. data/lib/oauthclient.rb +110 -0
  22. data/sample/async.rb +8 -0
  23. data/sample/auth.rb +11 -0
  24. data/sample/cookie.rb +18 -0
  25. data/sample/dav.rb +103 -0
  26. data/sample/howto.rb +49 -0
  27. data/sample/oauth_buzz.rb +57 -0
  28. data/sample/oauth_friendfeed.rb +59 -0
  29. data/sample/oauth_twitter.rb +61 -0
  30. data/sample/ssl/0cert.pem +22 -0
  31. data/sample/ssl/0key.pem +30 -0
  32. data/sample/ssl/1000cert.pem +19 -0
  33. data/sample/ssl/1000key.pem +18 -0
  34. data/sample/ssl/htdocs/index.html +10 -0
  35. data/sample/ssl/ssl_client.rb +22 -0
  36. data/sample/ssl/webrick_httpsd.rb +29 -0
  37. data/sample/stream.rb +21 -0
  38. data/sample/thread.rb +27 -0
  39. data/sample/wcat.rb +21 -0
  40. data/test/ca-chain.cert +44 -0
  41. data/test/ca.cert +23 -0
  42. data/test/client.cert +19 -0
  43. data/test/client.key +15 -0
  44. data/test/helper.rb +129 -0
  45. data/test/htdigest +1 -0
  46. data/test/htpasswd +2 -0
  47. data/test/runner.rb +2 -0
  48. data/test/server.cert +19 -0
  49. data/test/server.key +15 -0
  50. data/test/sslsvr.rb +65 -0
  51. data/test/subca.cert +21 -0
  52. data/test/test_auth.rb +321 -0
  53. data/test/test_cookie.rb +412 -0
  54. data/test/test_hexdump.rb +14 -0
  55. data/test/test_http-access2.rb +507 -0
  56. data/test/test_httpclient.rb +1801 -0
  57. data/test/test_include_client.rb +52 -0
  58. data/test/test_ssl.rb +235 -0
  59. metadata +102 -0
@@ -0,0 +1,186 @@
1
+ # HTTPClient - HTTP client library.
2
+ # Copyright (C) 2000-2012 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
+ #
4
+ # This program is copyrighted free software by NAKAMURA, Hiroshi. You can
5
+ # redistribute it and/or modify it under the same terms of Ruby's license;
6
+ # either the dual license version in 2003, or any later version.
7
+
8
+
9
+ unless ''.respond_to?(:bytesize)
10
+ class String
11
+ alias bytesize size
12
+ end
13
+ end
14
+
15
+ if RUBY_VERSION < "1.9.3"
16
+ require 'uri'
17
+ module URI
18
+ class Generic
19
+ def hostname
20
+ v = self.host
21
+ /\A\[(.*)\]\z/ =~ v ? $1 : v
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ class HTTPClient
28
+
29
+
30
+ # A module for common function.
31
+ module Util
32
+
33
+ # URI abstraction; Addressable::URI or URI
34
+ require 'uri'
35
+ begin
36
+ require 'addressable/uri'
37
+ # Older versions doesn't have #default_port
38
+ unless Addressable::URI.instance_methods.include?(:default_port) # 1.9 only
39
+ raise LoadError
40
+ end
41
+ class AddressableURI < Addressable::URI
42
+ # Overwrites the original definition just for one line...
43
+ def authority
44
+ self.host && @authority ||= (begin
45
+ authority = ""
46
+ if self.userinfo != nil
47
+ authority << "#{self.userinfo}@"
48
+ end
49
+ authority << self.host
50
+ if self.port != self.default_port # ...HERE! Compares with default_port because self.port is not nil in this wrapper.
51
+ authority << ":#{self.port}"
52
+ end
53
+ authority
54
+ end)
55
+ end
56
+
57
+ # HTTPClient expects urify("http://foo/").port to be not nil but 80 like URI.
58
+ def port
59
+ super || default_port
60
+ end
61
+
62
+ # Captured from uri/generic.rb
63
+ def hostname
64
+ v = self.host
65
+ /\A\[(.*)\]\z/ =~ v ? $1 : v
66
+ end
67
+ end
68
+ AddressableEnabled = true
69
+ rescue LoadError
70
+ AddressableEnabled = false
71
+ end
72
+
73
+ # Keyword argument helper.
74
+ # args:: given arguments.
75
+ # *field:: a list of arguments to be extracted.
76
+ #
77
+ # You can extract 3 arguments (a, b, c) with:
78
+ #
79
+ # include Util
80
+ # def my_method(*args)
81
+ # a, b, c = keyword_argument(args, :a, :b, :c)
82
+ # ...
83
+ # end
84
+ # my_method(1, 2, 3)
85
+ # my_method(:b => 2, :a = 1)
86
+ #
87
+ # instead of;
88
+ #
89
+ # def my_method(a, b, c)
90
+ # ...
91
+ # end
92
+ #
93
+ def keyword_argument(args, *field)
94
+ if args.size == 1 and Hash === args[0]
95
+ h = args[0]
96
+ if field.any? { |f| h.key?(f) }
97
+ return h.values_at(*field)
98
+ end
99
+ end
100
+ args
101
+ end
102
+
103
+ # Keyword argument to hash helper.
104
+ # args:: given arguments.
105
+ # *field:: a list of arguments to be extracted.
106
+ #
107
+ # Returns hash which has defined keys. When a Hash given, returns it
108
+ # including undefined keys. When an Array given, returns a Hash which only
109
+ # includes defined keys.
110
+ def argument_to_hash(args, *field)
111
+ return nil if args.empty?
112
+ if args.size == 1 and Hash === args[0]
113
+ h = args[0]
114
+ if field.any? { |f| h.key?(f) }
115
+ return h
116
+ end
117
+ end
118
+ h = {}
119
+ field.each_with_index do |e, idx|
120
+ h[e] = args[idx]
121
+ end
122
+ h
123
+ end
124
+
125
+ # Gets an URI instance.
126
+ def urify(uri)
127
+ if uri.nil?
128
+ nil
129
+ elsif uri.is_a?(URI)
130
+ uri
131
+ elsif AddressableEnabled
132
+ AddressableURI.parse(uri.to_s)
133
+ else
134
+ URI.parse(uri.to_s)
135
+ end
136
+ end
137
+ module_function :urify
138
+
139
+ # Returns true if the given 2 URIs have a part_of relationship.
140
+ # * the same scheme
141
+ # * the same host String (no host resolution or IP-addr conversion)
142
+ # * the same port number
143
+ # * target URI's path starts with base URI's path.
144
+ def uri_part_of(uri, part)
145
+ ((uri.scheme == part.scheme) and
146
+ (uri.host == part.host) and
147
+ (uri.port == part.port) and
148
+ uri.path.upcase.index(part.path.upcase) == 0)
149
+ end
150
+ module_function :uri_part_of
151
+
152
+ # Returns parent directory URI of the given URI.
153
+ def uri_dirname(uri)
154
+ uri = uri.clone
155
+ uri.path = uri.path.sub(/\/[^\/]*\z/, '/')
156
+ uri
157
+ end
158
+ module_function :uri_dirname
159
+
160
+ # Finds a value of a Hash.
161
+ def hash_find_value(hash, &block)
162
+ v = hash.find(&block)
163
+ v ? v[1] : nil
164
+ end
165
+ module_function :hash_find_value
166
+
167
+ # Gets a string to be used as a binary buffer
168
+ def get_buf
169
+ buf = ''
170
+ defined?(Encoding::ASCII_8BIT) && buf.force_encoding(Encoding::ASCII_8BIT)
171
+ buf
172
+ end
173
+ module_function :get_buf
174
+
175
+ # Checks if the given URI is https.
176
+ def https?(uri)
177
+ uri.scheme && uri.scheme.downcase == 'https'
178
+ end
179
+
180
+ def http?(uri)
181
+ uri.scheme && uri.scheme.downcase == 'http'
182
+ end
183
+ end
184
+
185
+
186
+ end
@@ -0,0 +1,3 @@
1
+ class HTTPClient
2
+ VERSION = '2.3.3'
3
+ end