wrest 1.0.0.beta2-universal-java-1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/CHANGELOG +59 -0
  2. data/LICENCE +7 -0
  3. data/README.rdoc +127 -0
  4. data/bin/wrest +3 -0
  5. data/bin/wrest_shell.rb +21 -0
  6. data/lib/wrest.rb +101 -0
  7. data/lib/wrest.rbc +1900 -0
  8. data/lib/wrest/components.rb +20 -0
  9. data/lib/wrest/components.rbc +217 -0
  10. data/lib/wrest/components/container.rb +185 -0
  11. data/lib/wrest/components/container.rbc +2466 -0
  12. data/lib/wrest/components/container/alias_accessors.rb +66 -0
  13. data/lib/wrest/components/container/alias_accessors.rbc +905 -0
  14. data/lib/wrest/components/container/typecaster.rb +127 -0
  15. data/lib/wrest/components/container/typecaster.rbc +1985 -0
  16. data/lib/wrest/components/mutators.rb +39 -0
  17. data/lib/wrest/components/mutators.rbc +650 -0
  18. data/lib/wrest/components/mutators/base.rb +56 -0
  19. data/lib/wrest/components/mutators/base.rbc +702 -0
  20. data/lib/wrest/components/mutators/camel_to_snake_case.rb +22 -0
  21. data/lib/wrest/components/mutators/camel_to_snake_case.rbc +360 -0
  22. data/lib/wrest/components/mutators/xml_mini_type_caster.rb +43 -0
  23. data/lib/wrest/components/mutators/xml_mini_type_caster.rbc +679 -0
  24. data/lib/wrest/components/mutators/xml_simple_type_caster.rb +37 -0
  25. data/lib/wrest/components/mutators/xml_simple_type_caster.rbc +559 -0
  26. data/lib/wrest/components/translators.rb +28 -0
  27. data/lib/wrest/components/translators.rbc +517 -0
  28. data/lib/wrest/components/translators/content_types.rb +20 -0
  29. data/lib/wrest/components/translators/content_types.rbc +339 -0
  30. data/lib/wrest/components/translators/json.rb +25 -0
  31. data/lib/wrest/components/translators/json.rbc +462 -0
  32. data/lib/wrest/components/translators/xml.rb +24 -0
  33. data/lib/wrest/components/translators/xml.rbc +457 -0
  34. data/lib/wrest/core_ext/hash.rb +5 -0
  35. data/lib/wrest/core_ext/hash.rbc +182 -0
  36. data/lib/wrest/core_ext/hash/conversions.rb +44 -0
  37. data/lib/wrest/core_ext/hash/conversions.rbc +501 -0
  38. data/lib/wrest/core_ext/string.rb +5 -0
  39. data/lib/wrest/core_ext/string.rbc +182 -0
  40. data/lib/wrest/core_ext/string/conversions.rb +23 -0
  41. data/lib/wrest/core_ext/string/conversions.rbc +471 -0
  42. data/lib/wrest/curl.rb +49 -0
  43. data/lib/wrest/curl.rbc +704 -0
  44. data/lib/wrest/curl/delete.rb +23 -0
  45. data/lib/wrest/curl/get.rb +23 -0
  46. data/lib/wrest/curl/options.rb +16 -0
  47. data/lib/wrest/curl/post.rb +23 -0
  48. data/lib/wrest/curl/put.rb +23 -0
  49. data/lib/wrest/curl/request.rb +97 -0
  50. data/lib/wrest/curl/response.rb +71 -0
  51. data/lib/wrest/curl/session.rb +57 -0
  52. data/lib/wrest/exceptions.rb +33 -0
  53. data/lib/wrest/exceptions.rbc +312 -0
  54. data/lib/wrest/http_shared.rb +23 -0
  55. data/lib/wrest/http_shared.rbc +279 -0
  56. data/lib/wrest/http_shared/headers.rb +343 -0
  57. data/lib/wrest/http_shared/headers.rbc +353 -0
  58. data/lib/wrest/http_shared/standard_headers.rb +21 -0
  59. data/lib/wrest/http_shared/standard_headers.rbc +336 -0
  60. data/lib/wrest/http_shared/standard_tokens.rb +18 -0
  61. data/lib/wrest/http_shared/standard_tokens.rbc +316 -0
  62. data/lib/wrest/multipart.rb +52 -0
  63. data/lib/wrest/native.rb +33 -0
  64. data/lib/wrest/native.rbc +513 -0
  65. data/lib/wrest/native/connection_factory.rb +23 -0
  66. data/lib/wrest/native/connection_factory.rbc +445 -0
  67. data/lib/wrest/native/delete.rb +23 -0
  68. data/lib/wrest/native/delete.rbc +371 -0
  69. data/lib/wrest/native/get.rb +51 -0
  70. data/lib/wrest/native/get.rbc +855 -0
  71. data/lib/wrest/native/options.rb +23 -0
  72. data/lib/wrest/native/options.rbc +347 -0
  73. data/lib/wrest/native/post.rb +23 -0
  74. data/lib/wrest/native/post.rbc +388 -0
  75. data/lib/wrest/native/post_multipart.rb +32 -0
  76. data/lib/wrest/native/put.rb +23 -0
  77. data/lib/wrest/native/put.rbc +388 -0
  78. data/lib/wrest/native/put_multipart.rb +32 -0
  79. data/lib/wrest/native/redirection.rb +38 -0
  80. data/lib/wrest/native/redirection.rbc +520 -0
  81. data/lib/wrest/native/request.rb +94 -0
  82. data/lib/wrest/native/request.rbc +1675 -0
  83. data/lib/wrest/native/response.rb +120 -0
  84. data/lib/wrest/native/response.rbc +2150 -0
  85. data/lib/wrest/native/session.rb +57 -0
  86. data/lib/wrest/native/session.rbc +1372 -0
  87. data/lib/wrest/resource.rb +18 -0
  88. data/lib/wrest/resource.rbc +163 -0
  89. data/lib/wrest/resource/base.rb +99 -0
  90. data/lib/wrest/resource/base.rbc +2115 -0
  91. data/lib/wrest/resource/collection.rb +12 -0
  92. data/lib/wrest/resource/state.rb +6 -0
  93. data/lib/wrest/test.rb +1 -0
  94. data/lib/wrest/test/request_patches.rb +5 -0
  95. data/lib/wrest/uri.rb +160 -0
  96. data/lib/wrest/uri.rbc +2599 -0
  97. data/lib/wrest/uri_template.rb +49 -0
  98. data/lib/wrest/uri_template.rbc +505 -0
  99. data/lib/wrest/version.rb +23 -0
  100. data/lib/wrest/version.rbc +372 -0
  101. metadata +231 -0
@@ -0,0 +1,23 @@
1
+ # Copyright 2009 Sidu Ponnappa
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at native://www.apache.org/licenses/LICENSE-2.0
6
+ # Unless required by applicable law or agreed to in writing, software distributed under the License
7
+ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module Wrest
11
+ # Contains functionality that is independent of
12
+ # the underlying HTTP libs
13
+ module HttpShared
14
+ end
15
+ end
16
+
17
+ require "#{Wrest::Root}/wrest/http_shared/headers"
18
+ require "#{Wrest::Root}/wrest/http_shared/standard_headers"
19
+ require "#{Wrest::Root}/wrest/http_shared/standard_tokens"
20
+
21
+ # Set up a shorter convenience API for constants
22
+ Wrest::H = Wrest::HttpShared::StandardHeaders
23
+ Wrest::T = Wrest::HttpShared::StandardTokens
@@ -0,0 +1,279 @@
1
+ !RBIX
2
+ 0
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 117
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 5
40
+ 45
41
+ 0
42
+ 5
43
+ 43
44
+ 6
45
+ 47
46
+ 49
47
+ 7
48
+ 0
49
+ 7
50
+ 8
51
+ 63
52
+ 2
53
+ 47
54
+ 49
55
+ 9
56
+ 1
57
+ 15
58
+ 5
59
+ 45
60
+ 0
61
+ 10
62
+ 43
63
+ 6
64
+ 47
65
+ 49
66
+ 7
67
+ 0
68
+ 7
69
+ 11
70
+ 63
71
+ 2
72
+ 47
73
+ 49
74
+ 9
75
+ 1
76
+ 15
77
+ 5
78
+ 45
79
+ 0
80
+ 12
81
+ 43
82
+ 6
83
+ 47
84
+ 49
85
+ 7
86
+ 0
87
+ 7
88
+ 13
89
+ 63
90
+ 2
91
+ 47
92
+ 49
93
+ 9
94
+ 1
95
+ 15
96
+ 45
97
+ 0
98
+ 14
99
+ 7
100
+ 15
101
+ 45
102
+ 0
103
+ 16
104
+ 43
105
+ 17
106
+ 43
107
+ 18
108
+ 49
109
+ 19
110
+ 2
111
+ 15
112
+ 45
113
+ 0
114
+ 20
115
+ 7
116
+ 21
117
+ 45
118
+ 0
119
+ 22
120
+ 43
121
+ 17
122
+ 43
123
+ 23
124
+ 49
125
+ 19
126
+ 2
127
+ 15
128
+ 2
129
+ 11
130
+ I
131
+ 6
132
+ I
133
+ 0
134
+ I
135
+ 0
136
+ I
137
+ 0
138
+ n
139
+ p
140
+ 24
141
+ x
142
+ 5
143
+ Wrest
144
+ x
145
+ 11
146
+ open_module
147
+ x
148
+ 15
149
+ __module_init__
150
+ M
151
+ 1
152
+ n
153
+ n
154
+ x
155
+ 5
156
+ Wrest
157
+ i
158
+ 12
159
+ 5
160
+ 66
161
+ 99
162
+ 7
163
+ 0
164
+ 65
165
+ 49
166
+ 1
167
+ 2
168
+ 15
169
+ 1
170
+ 11
171
+ I
172
+ 3
173
+ I
174
+ 0
175
+ I
176
+ 0
177
+ I
178
+ 0
179
+ n
180
+ p
181
+ 2
182
+ x
183
+ 10
184
+ HttpShared
185
+ x
186
+ 11
187
+ open_module
188
+ p
189
+ 3
190
+ I
191
+ 2
192
+ I
193
+ d
194
+ I
195
+ c
196
+ x
197
+ 47
198
+ /Users/sidu/Work/wrest/lib/wrest/http_shared.rb
199
+ p
200
+ 0
201
+ x
202
+ 13
203
+ attach_method
204
+ n
205
+ x
206
+ 4
207
+ Root
208
+ x
209
+ 4
210
+ to_s
211
+ s
212
+ 26
213
+ /wrest/http_shared/headers
214
+ x
215
+ 7
216
+ require
217
+ n
218
+ s
219
+ 35
220
+ /wrest/http_shared/standard_headers
221
+ n
222
+ s
223
+ 34
224
+ /wrest/http_shared/standard_tokens
225
+ n
226
+ x
227
+ 1
228
+ H
229
+ n
230
+ x
231
+ 10
232
+ HttpShared
233
+ x
234
+ 15
235
+ StandardHeaders
236
+ x
237
+ 9
238
+ const_set
239
+ n
240
+ x
241
+ 1
242
+ T
243
+ n
244
+ x
245
+ 14
246
+ StandardTokens
247
+ p
248
+ 13
249
+ I
250
+ 0
251
+ I
252
+ a
253
+ I
254
+ 1a
255
+ I
256
+ 11
257
+ I
258
+ 2d
259
+ I
260
+ 12
261
+ I
262
+ 40
263
+ I
264
+ 13
265
+ I
266
+ 53
267
+ I
268
+ 16
269
+ I
270
+ 63
271
+ I
272
+ 17
273
+ I
274
+ 75
275
+ x
276
+ 47
277
+ /Users/sidu/Work/wrest/lib/wrest/http_shared.rb
278
+ p
279
+ 0
@@ -0,0 +1,343 @@
1
+ #
2
+ # Header module.
3
+ #
4
+ # Provides access to headers in the mixed-into class as a hash-like
5
+ # object, except with case-insensitive keys. Also provides
6
+ # methods for accessing commonly-used header values in a more
7
+ # convenient format.
8
+ #
9
+ # Sourced from Net::HTTP and then modified to be generic
10
+ module Wrest
11
+ module HttpShared
12
+ module Headers
13
+ # Returns the header field corresponding to the case-insensitive key.
14
+ # For example, a key of "Content-Type" might return "text/html"
15
+ def [](key)
16
+ headers[key] || headers[key.downcase]
17
+ end
18
+
19
+ # # Sets the header field corresponding to the case-insensitive key.
20
+ # def []=(key, val)
21
+ # unless val
22
+ # headers.delete key.downcase
23
+ # return val
24
+ # end
25
+ # headers[key.downcase] = [val]
26
+ # end
27
+ #
28
+ # # [Ruby 1.8.3]
29
+ # # Adds header field instead of replace.
30
+ # # Second argument +val+ must be a String.
31
+ # # See also #[]=, #[] and #get_fields.
32
+ # #
33
+ # # request.add_field 'X-My-Header', 'a'
34
+ # # p request['X-My-Header'] #=> "a"
35
+ # # p request.get_fields('X-My-Header') #=> ["a"]
36
+ # # request.add_field 'X-My-Header', 'b'
37
+ # # p request['X-My-Header'] #=> "a, b"
38
+ # # p request.get_fields('X-My-Header') #=> ["a", "b"]
39
+ # # request.add_field 'X-My-Header', 'c'
40
+ # # p request['X-My-Header'] #=> "a, b, c"
41
+ # # p request.get_fields('X-My-Header') #=> ["a", "b", "c"]
42
+ # #
43
+ # def add_field(key, val)
44
+ # if headers.key?(key.downcase)
45
+ # headers[key.downcase].push val
46
+ # else
47
+ # headers[key.downcase] = [val]
48
+ # end
49
+ # end
50
+ #
51
+ # # [Ruby 1.8.3]
52
+ # # Returns an array of header field strings corresponding to the
53
+ # # case-insensitive +key+. This method allows you to get duplicated
54
+ # # header fields without any processing. See also #[].
55
+ # #
56
+ # # p response.get_fields('Set-Cookie')
57
+ # # #=> ["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23",
58
+ # # "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"]
59
+ # # p response['Set-Cookie']
60
+ # # #=> "session=al98axx; expires=Fri, 31-Dec-1999 23:58:23, query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"
61
+ # #
62
+ # def get_fields(key)
63
+ # return nil unless headers[key.downcase]
64
+ # headers[key.downcase].dup
65
+ # end
66
+ #
67
+ # # Returns the header field corresponding to the case-insensitive key.
68
+ # # Returns the default value +args+, or the result of the block, or nil,
69
+ # # if there's no header field named key. See Hash#fetch
70
+ # def fetch(key, *args, &block) #:yield: +key+
71
+ # a = headers.fetch(key.downcase, *args, &block)
72
+ # a.join(', ')
73
+ # end
74
+ #
75
+ # # Iterates for each header names and values.
76
+ # def each_header #:yield: +key+, +value+
77
+ # headers.each do |k,va|
78
+ # yield k, va.join(', ')
79
+ # end
80
+ # end
81
+ #
82
+ # alias each each_header
83
+ #
84
+ # # Iterates for each header names.
85
+ # def each_name(&block) #:yield: +key+
86
+ # headers.each_key(&block)
87
+ # end
88
+ #
89
+ # alias each_key each_name
90
+ #
91
+ # # Iterates for each capitalized header names.
92
+ # def each_capitalized_name(&block) #:yield: +key+
93
+ # headers.each_key do |k|
94
+ # yield capitalize(k)
95
+ # end
96
+ # end
97
+ #
98
+ # # Iterates for each header values.
99
+ # def each_value #:yield: +value+
100
+ # headers.each_value do |va|
101
+ # yield va.join(', ')
102
+ # end
103
+ # end
104
+ #
105
+ # # Removes a header field.
106
+ # def delete(key)
107
+ # headers.delete(key.downcase)
108
+ # end
109
+ #
110
+ # # true if +key+ header exists.
111
+ # def key?(key)
112
+ # headers.key?(key.downcase)
113
+ # end
114
+ #
115
+ # # Returns a Hash consist of header names and values.
116
+ # def to_hash
117
+ # headers.dup
118
+ # end
119
+ #
120
+ # # As for #each_header, except the keys are provided in capitalized form.
121
+ # def each_capitalized
122
+ # headers.each do |k,v|
123
+ # yield capitalize(k), v.join(', ')
124
+ # end
125
+ # end
126
+ #
127
+ # alias canonical_each each_capitalized
128
+ #
129
+ # def capitalize(name)
130
+ # name.split(/-/).map {|s| s.capitalize }.join('-')
131
+ # end
132
+ # private :capitalize
133
+ #
134
+ # # Returns an Array of Range objects which represents Range: header field,
135
+ # # or +nil+ if there is no such header.
136
+ # def range
137
+ # return nil unless headers['range']
138
+ # self['Range'].split(/,/).map {|spec|
139
+ # m = /bytes\s*=\s*(\d+)?\s*-\s*(\d+)?/i.match(spec) or
140
+ # raise HTTPHeaderSyntaxError, "wrong Range: #{spec}"
141
+ # d1 = m[1].to_i
142
+ # d2 = m[2].to_i
143
+ # if m[1] and m[2] then d1..d2
144
+ # elsif m[1] then d1..-1
145
+ # elsif m[2] then -d2..-1
146
+ # else
147
+ # raise HTTPHeaderSyntaxError, 'range is not specified'
148
+ # end
149
+ # }
150
+ # end
151
+ #
152
+ # # Set Range: header from Range (arg r) or beginning index and
153
+ # # length from it (arg idx&len).
154
+ # #
155
+ # # req.range = (0..1023)
156
+ # # req.set_range 0, 1023
157
+ # #
158
+ # def set_range(r, e = nil)
159
+ # unless r
160
+ # headers.delete 'range'
161
+ # return r
162
+ # end
163
+ # r = (r...r+e) if e
164
+ # case r
165
+ # when Numeric
166
+ # n = r.to_i
167
+ # rangestr = (n > 0 ? "0-#{n-1}" : "-#{-n}")
168
+ # when Range
169
+ # first = r.first
170
+ # last = r.last
171
+ # last -= 1 if r.exclude_end?
172
+ # if last == -1
173
+ # rangestr = (first > 0 ? "#{first}-" : "-#{-first}")
174
+ # else
175
+ # raise HTTPHeaderSyntaxError, 'range.first is negative' if first < 0
176
+ # raise HTTPHeaderSyntaxError, 'range.last is negative' if last < 0
177
+ # raise HTTPHeaderSyntaxError, 'must be .first < .last' if first > last
178
+ # rangestr = "#{first}-#{last}"
179
+ # end
180
+ # else
181
+ # raise TypeError, 'Range/Integer is required'
182
+ # end
183
+ # headers['range'] = ["bytes=#{rangestr}"]
184
+ # r
185
+ # end
186
+ #
187
+ # alias range= set_range
188
+ #
189
+ # # Returns an Integer object which represents the Content-Length: header field
190
+ # # or +nil+ if that field is not provided.
191
+ # def content_length
192
+ # return nil unless key?('Content-Length')
193
+ # len = self['Content-Length'].slice(/\d+/) or
194
+ # raise HTTPHeaderSyntaxError, 'wrong Content-Length format'
195
+ # len.to_i
196
+ # end
197
+ #
198
+ # def content_length=(len)
199
+ # unless len
200
+ # headers.delete 'content-length'
201
+ # return nil
202
+ # end
203
+ # headers['content-length'] = [len.to_i.to_s]
204
+ # end
205
+ #
206
+ # # Returns "true" if the "transfer-encoding" header is present and
207
+ # # set to "chunked". This is an HTTP/1.1 feature, allowing the
208
+ # # the content to be sent in "chunks" without at the outset
209
+ # # stating the entire content length.
210
+ # def chunked?
211
+ # return false unless headers['transfer-encoding']
212
+ # field = self['Transfer-Encoding']
213
+ # (/(?:\A|[^\-\w])chunked(?![\-\w])/i =~ field) ? true : false
214
+ # end
215
+ #
216
+ # # Returns a Range object which represents Content-Range: header field.
217
+ # # This indicates, for a partial entity body, where this fragment
218
+ # # fits inside the full entity body, as range of byte offsets.
219
+ # def content_range
220
+ # return nil unless headers['content-range']
221
+ # m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) or
222
+ # raise HTTPHeaderSyntaxError, 'wrong Content-Range format'
223
+ # m[1].to_i .. m[2].to_i + 1
224
+ # end
225
+ #
226
+ # # The length of the range represented in Content-Range: header.
227
+ # def range_length
228
+ # r = content_range() or return nil
229
+ # r.end - r.begin
230
+ # end
231
+ #
232
+ # # Returns a content type string such as "text/html".
233
+ # # This method returns nil if Content-Type: header field does not exist.
234
+ # def content_type
235
+ # return nil unless main_type()
236
+ # if sub_type()
237
+ # "#{main_type()}/#{sub_type()}"
238
+ # else
239
+ # main_type()
240
+ # end
241
+ # end
242
+ #
243
+ # # Returns a content type string such as "text".
244
+ # # This method returns nil if Content-Type: header field does not exist.
245
+ # def main_type
246
+ # return nil unless headers['content-type']
247
+ # self['Content-Type'].split(';').first.to_s.split('/')[0].to_s.strip
248
+ # end
249
+ #
250
+ # # Returns a content type string such as "html".
251
+ # # This method returns nil if Content-Type: header field does not exist
252
+ # # or sub-type is not given (e.g. "Content-Type: text").
253
+ # def sub_type
254
+ # return nil unless headers['content-type']
255
+ # main, sub = *self['Content-Type'].split(';').first.to_s.split('/')
256
+ # return nil unless sub
257
+ # sub.strip
258
+ # end
259
+ #
260
+ # # Returns content type parameters as a Hash as like
261
+ # # {"charset" => "iso-2022-jp"}.
262
+ # def type_params
263
+ # result = {}
264
+ # list = self['Content-Type'].to_s.split(';')
265
+ # list.shift
266
+ # list.each do |param|
267
+ # k, v = *param.split('=', 2)
268
+ # result[k.strip] = v.strip
269
+ # end
270
+ # result
271
+ # end
272
+ #
273
+ # # Set Content-Type: header field by +type+ and +params+.
274
+ # # +type+ must be a String, +params+ must be a Hash.
275
+ # def set_content_type(type, params = {})
276
+ # headers['content-type'] = [type + params.map{|k,v|"; #{k}=#{v}"}.join('')]
277
+ # end
278
+ #
279
+ # alias content_type= set_content_type
280
+ #
281
+ # # Set header fields and a body from HTML form data.
282
+ # # +params+ should be a Hash containing HTML form data.
283
+ # # Optional argument +sep+ means data record separator.
284
+ # #
285
+ # # This method also set Content-Type: header field to
286
+ # # application/x-www-form-urlencoded.
287
+ # #
288
+ # # Example:
289
+ # # http.form_data = {"q" => "ruby", "lang" => "en"}
290
+ # # http.form_data = {"q" => ["ruby", "perl"], "lang" => "en"}
291
+ # # http.set_form_data({"q" => "ruby", "lang" => "en"}, ';')
292
+ # #
293
+ # def set_form_data(params, sep = '&')
294
+ # self.body = params.map {|k, v| encode_kvpair(k, v) }.flatten.join(sep)
295
+ # self.content_type = 'application/x-www-form-urlencoded'
296
+ # end
297
+ #
298
+ # alias form_data= set_form_data
299
+ #
300
+ # def encode_kvpair(k, vs)
301
+ # Array(vs).map {|v| "#{urlencode(k)}=#{urlencode(v.to_s)}" }
302
+ # end
303
+ # private :encode_kvpair
304
+ #
305
+ # def urlencode(str)
306
+ # str.dup.force_encoding('ASCII-8BIT').gsub(/[^a-zA-Z0-9_\.\-]/){'%%%02x' % $&.ord}
307
+ # end
308
+ # private :urlencode
309
+ #
310
+ # # Set the Authorization: header for "Basic" authorization.
311
+ # def basic_auth(account, password)
312
+ # headers['authorization'] = [basic_encode(account, password)]
313
+ # end
314
+ #
315
+ # # Set Proxy-Authorization: header for "Basic" authorization.
316
+ # def proxy_basic_auth(account, password)
317
+ # headers['proxy-authorization'] = [basic_encode(account, password)]
318
+ # end
319
+ #
320
+ # def basic_encode(account, password)
321
+ # 'Basic ' + ["#{account}:#{password}"].pack('m').delete("\r\n")
322
+ # end
323
+ # private :basic_encode
324
+ #
325
+ # def connection_close?
326
+ # tokens(headers['connection']).include?('close') or
327
+ # tokens(headers['proxy-connection']).include?('close')
328
+ # end
329
+ #
330
+ # def connection_keep_alive?
331
+ # tokens(headers['connection']).include?('keep-alive') or
332
+ # tokens(headers['proxy-connection']).include?('keep-alive')
333
+ # end
334
+ #
335
+ # def tokens(vals)
336
+ # return [] unless vals
337
+ # vals.map {|v| v.split(',') }.flatten\
338
+ # .reject {|str| str.strip.empty? }\
339
+ # .map {|tok| tok.strip.downcase }
340
+ # end
341
+ end
342
+ end
343
+ end