httpclient 2.7.2 → 2.9.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.
data/test/subca.cert CHANGED
@@ -1,21 +1,20 @@
1
1
  -----BEGIN CERTIFICATE-----
2
- MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA8MQswCQYDVQQGDAJKUDES
2
+ MIIDODCCAiCgAwIBAgIBAjANBgkqhkiG9w0BAQsFADA8MQswCQYDVQQGEwJKUDES
3
3
  MBAGA1UECgwJSklOLkdSLkpQMQwwCgYDVQQLDANSUlIxCzAJBgNVBAMMAkNBMB4X
4
- DTA0MDEzMDAwNDMyN1oXDTM1MDEyMjAwNDMyN1owPzELMAkGA1UEBgwCSlAxEjAQ
4
+ DTI1MDIxMjA4NDIzMVoXDTM0MDIxMDA4NDIzMVowPzELMAkGA1UEBhMCSlAxEjAQ
5
5
  BgNVBAoMCUpJTi5HUi5KUDEMMAoGA1UECwwDUlJSMQ4wDAYDVQQDDAVTdWJDQTCC
6
- ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJ0Ou7AyRcRXnB/kVHv/6kwe
7
- ANzgg/DyJfsAUqW90m7Lu1nqyug8gK0RBd77yU0w5HOAMHTVSdpjZK0g2sgx4Mb1
8
- d/213eL9TTl5MRVEChTvQr8q5DVG/8fxPPE7fMI8eOAzd98/NOAChk+80r4Sx7fC
9
- kGVEE1bKwY1MrUsUNjOY2d6t3M4HHV3HX1V8ShuKfsHxgCmLzdI8U+5CnQedFgkm
10
- 3e+8tr8IX5RR1wA1Ifw9VadF7OdI/bGMzog/Q8XCLf+WPFjnK7Gcx6JFtzF6Gi4x
11
- 4dp1Xl45JYiVvi9zQ132wu8A1pDHhiNgQviyzbP+UjcB/tsOpzBQF8abYzgEkWEC
12
- AwEAAaNyMHAwDwYDVR0TAQH/BAUwAwEB/zAxBglghkgBhvhCAQ0EJBYiUnVieS9P
13
- cGVuU1NMIEdlbm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IVATE KEY-----
data/test/subca.srl ADDED
@@ -0,0 +1 @@
1
+ 1A196228872FBD912F1AED26DF7847E9BE54F0EA
data/test/test_auth.rb CHANGED
@@ -2,7 +2,6 @@ require File.expand_path('helper', File.dirname(__FILE__))
2
2
  require 'digest/md5'
3
3
  require 'rack'
4
4
  require 'rack/lint'
5
- require 'rack/showexceptions'
6
5
  require 'rack-ntlm'
7
6
 
8
7
  class TestAuth < Test::Unit::TestCase
@@ -128,6 +127,10 @@ class TestAuth < Test::Unit::TestCase
128
127
  def data_size
129
128
  @active && @value ? @value.size : 0
130
129
  end
130
+
131
+ def value
132
+ @value ||= ""
133
+ end
131
134
  end
132
135
  end
133
136
  end
@@ -177,7 +180,7 @@ class TestAuth < Test::Unit::TestCase
177
180
  c.www_auth.basic_auth.instance_eval { @scheme = "BASIC" }
178
181
  #
179
182
  c.force_basic_auth = true
180
- c.debug_dev = str = ''
183
+ c.debug_dev = str = ''.dup
181
184
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
182
185
  assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth"))
183
186
  assert_equal('Authorization: Basic YWRtaW46YWRtaW4='.upcase, str.split(/\r?\n/)[5].upcase)
@@ -231,11 +234,11 @@ class TestAuth < Test::Unit::TestCase
231
234
  c.www_auth.basic_auth.instance_eval { @scheme = "BASIC" }
232
235
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
233
236
 
234
- 100.times.map { |idx|
237
+ 20.times.map { |idx|
235
238
  Thread.new(idx) { |idx2|
236
239
  Thread.abort_on_exception = true
237
240
  Thread.pass
238
- c.get("http://localhost:#{serverport}/basic_auth?#{idx2}")
241
+ assert_equal('basic_auth OK', c.get("http://localhost:#{serverport}/basic_auth?#{idx2}").body)
239
242
  }
240
243
  }.map { |t|
241
244
  t.join
@@ -250,7 +253,7 @@ class TestAuth < Test::Unit::TestCase
250
253
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
251
254
  assert_equal('basic_auth OK', c.get_content("http://localhost:#{serverport}/basic_auth/"))
252
255
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
253
- c.debug_dev = str = ''
256
+ c.debug_dev = str = ''.dup
254
257
  c.get_content("http://localhost:#{serverport}/basic_auth/sub/dir/")
255
258
  assert_match(/Authorization: Basic YWRtaW46YWRtaW4=/, str)
256
259
  end
@@ -266,7 +269,7 @@ class TestAuth < Test::Unit::TestCase
266
269
  c.set_auth("http://localhost:#{serverport}/", 'admin', 'admin')
267
270
  assert_equal('digest_auth OK', c.get_content("http://localhost:#{serverport}/digest_auth/"))
268
271
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
269
- c.debug_dev = str = ''
272
+ c.debug_dev = str = ''.dup
270
273
  c.get_content("http://localhost:#{serverport}/digest_auth/sub/dir/")
271
274
  assert_match(/Authorization: Digest/, str)
272
275
  end
@@ -312,7 +315,7 @@ class TestAuth < Test::Unit::TestCase
312
315
  c.set_auth('http://example.com/', 'admin', 'admin')
313
316
  c.test_loopback_http_response << "HTTP/1.0 401 Unauthorized\nWWW-Authenticate: Basic realm=\"foo\"\nWWW-Authenticate: Digest realm=\"foo\", nonce=\"nonce\", stale=false\nContent-Length: 2\n\nNG"
314
317
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
315
- c.debug_dev = str = ''
318
+ c.debug_dev = str = ''.dup
316
319
  c.get_content('http://example.com/')
317
320
  assert_match(/^Authorization: Digest/, str)
318
321
  end
@@ -328,7 +331,7 @@ class TestAuth < Test::Unit::TestCase
328
331
  c.set_proxy_auth('admin', 'admin')
329
332
  c.test_loopback_http_response << "HTTP/1.0 407 Unauthorized\nProxy-Authenticate: Basic realm=\"foo\"\nContent-Length: 2\n\nNG"
330
333
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
331
- c.debug_dev = str = ''
334
+ c.debug_dev = str = ''.dup
332
335
  c.get_content('http://example.com/')
333
336
  assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
334
337
  end
@@ -338,7 +341,7 @@ class TestAuth < Test::Unit::TestCase
338
341
  c.set_proxy_auth('admin', 'admin')
339
342
  c.force_basic_auth = true
340
343
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
341
- c.debug_dev = str = ''
344
+ c.debug_dev = str = ''.dup
342
345
  c.get_content('http://example.com/')
343
346
  assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
344
347
  end
@@ -350,7 +353,7 @@ class TestAuth < Test::Unit::TestCase
350
353
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
351
354
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
352
355
  c.get_content('http://www1.example.com/')
353
- c.debug_dev = str = ''
356
+ c.debug_dev = str = ''.dup
354
357
  c.get_content('http://www2.example.com/')
355
358
  assert_match(/Proxy-Authorization: Basic YWRtaW46YWRtaW4=/, str)
356
359
  end
@@ -364,7 +367,7 @@ class TestAuth < Test::Unit::TestCase
364
367
  ha1 = md5.hexdigest("admin:foo:admin")
365
368
  ha2 = md5.hexdigest("GET:/")
366
369
  response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
367
- c.debug_dev = str = ''
370
+ c.debug_dev = str = ''.dup
368
371
  c.get_content('http://example.com/')
369
372
  assert_match(/Proxy-Authorization: Digest/, str)
370
373
  assert_match(%r"response=\"#{response}\"", str)
@@ -395,7 +398,7 @@ class TestAuth < Test::Unit::TestCase
395
398
  ha1 = md5.hexdigest("admin:foo:admin")
396
399
  ha2 = md5.hexdigest("GET:/")
397
400
  response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
398
- c.debug_dev = str = ''
401
+ c.debug_dev = str = ''.dup
399
402
  c.get_content('http://example.com/')
400
403
  assert_match(/Proxy-Authorization: Digest/, str)
401
404
  assert_match(%r"response=\"#{response}\"", str)
@@ -412,7 +415,7 @@ class TestAuth < Test::Unit::TestCase
412
415
  ha2 = md5.hexdigest("GET:/")
413
416
  response = md5.hexdigest("#{ha1}:nonce:#{ha2}")
414
417
  c.get_content('http://www1.example.com/')
415
- c.debug_dev = str = ''
418
+ c.debug_dev = str = ''.dup
416
419
  c.get_content('http://www2.example.com/')
417
420
  assert_match(/Proxy-Authorization: Digest/, str)
418
421
  assert_match(%r"response=\"#{response}\"", str)
@@ -434,19 +437,19 @@ class TestAuth < Test::Unit::TestCase
434
437
  c.www_auth.oauth.set_config('http://photos.example.net/', config)
435
438
  c.www_auth.oauth.challenge('http://photos.example.net/')
436
439
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
437
- c.debug_dev = str = ''
440
+ c.debug_dev = str = ''.dup
438
441
  c.get_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
439
442
  assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
440
443
  assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
441
444
  #
442
445
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
443
- c.debug_dev = str = ''
446
+ c.debug_dev = str = ''.dup
444
447
  c.get_content('http://photos.example.net/photos?file=vacation.jpg&size=original')
445
448
  assert(str.index(%q(GET /photos?file=vacation.jpg&size=original)))
446
449
  assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="tR3%2BTy81lMeYAr%2FFid0kMTYa%2FWM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
447
450
  #
448
451
  c.test_loopback_http_response << "HTTP/1.0 200 OK\nContent-Length: 2\n\nOK"
449
- c.debug_dev = str = ''
452
+ c.debug_dev = str = ''.dup
450
453
  c.post_content('http://photos.example.net/photos', [[:file, 'vacation.jpg'], [:size, 'original']])
451
454
  assert(str.index(%q(POST /photos)))
452
455
  assert(str.index(%q(Authorization: OAuth realm="http://photos.example.net/", oauth_consumer_key="dpf43f3p2l4k3l03", oauth_nonce="kllo9940pd9333jh", oauth_signature="wPkvxykrw%2BBTdCcGqKr%2B3I%2BPsiM%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1191242096", oauth_token="nnch734d00sl2jdk", oauth_version="1.0")))
@@ -476,7 +479,7 @@ class TestAuth < Test::Unit::TestCase
476
479
  c.test_loopback_http_response << %Q(HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: NTLM TlRMTVNTUAACAAAAAAAAACgAAAABAAAAAAAAAAAAAAA=\r\nConnection: Keep-Alive\r\nContent-Length: 0\r\n\r\n)
477
480
  c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\na)
478
481
  c.test_loopback_http_response << %Q(HTTP/1.0 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: 1\r\n\r\nb)
479
- c.debug_dev = str = ''
482
+ c.debug_dev = str = ''.dup
480
483
  c.set_auth('http://www.example.org/', 'admin', 'admin')
481
484
  # Do NTLM negotiation
482
485
  c.get('http://www.example.org/foo')
@@ -485,7 +488,7 @@ class TestAuth < Test::Unit::TestCase
485
488
  assert_match(%r(Authorization: NTLM), str)
486
489
  assert_not_match(%r(Authorization: Basic), str)
487
490
  # ditto for other resource that is protected with NTLM
488
- c.debug_dev = str = ''
491
+ c.debug_dev = str = ''.dup
489
492
  c.get('http://www.example.org/foo/subdir')
490
493
  assert_not_match(%r(Authorization: NTLM), str)
491
494
  assert_not_match(%r(Authorization: Basic), str)
data/test/test_hexdump.rb CHANGED
@@ -5,8 +5,7 @@ require 'hexdump'
5
5
 
6
6
  class TestHexDump < Test::Unit::TestCase
7
7
  def test_encode
8
- str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376"
9
- str.force_encoding('BINARY') if str.respond_to?(:force_encoding)
8
+ str = "\032l\277\370\2429\216\236\351[{\{\262\350\274\376".b
10
9
  assert_equal(["00000000 1a6cbff8 a2398e9e e95b7b7b b2e8bcfe .l...9...[{{...."], HexDump.encode(str))
11
10
  end
12
11
  end if defined?(RUBY_ENGINE) && RUBY_ENGINE != "rbx" && RUBY_VERSION >= "1.9.0"
@@ -24,7 +24,7 @@ class TestClient < Test::Unit::TestCase
24
24
  def test_initialize
25
25
  setup_proxyserver
26
26
  escape_noproxy do
27
- @proxyio.string = ""
27
+ @proxyio.truncate(0)
28
28
  @client = HTTPAccess2::Client.new(proxyurl)
29
29
  assert_equal(urify(proxyurl), @client.proxy)
30
30
  assert_equal(200, @client.head(serverurl).status)
@@ -34,7 +34,7 @@ class TestClient < Test::Unit::TestCase
34
34
 
35
35
  def test_agent_name
36
36
  @client = HTTPAccess2::Client.new(nil, "agent_name_foo")
37
- str = ""
37
+ str = "".dup
38
38
  @client.debug_dev = str
39
39
  @client.get(serverurl)
40
40
  lines = str.split(/(?:\r?\n)+/)
@@ -44,7 +44,7 @@ class TestClient < Test::Unit::TestCase
44
44
 
45
45
  def test_from
46
46
  @client = HTTPAccess2::Client.new(nil, nil, "from_bar")
47
- str = ""
47
+ str = "".dup
48
48
  @client.debug_dev = str
49
49
  @client.get(serverurl)
50
50
  lines = str.split(/(?:\r?\n)+/)
@@ -53,7 +53,7 @@ class TestClient < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  def test_debug_dev
56
- str = ""
56
+ str = "".dup
57
57
  @client.debug_dev = str
58
58
  assert(str.empty?)
59
59
  @client.get(serverurl)
@@ -62,7 +62,7 @@ class TestClient < Test::Unit::TestCase
62
62
 
63
63
  def _test_protocol_version_http09
64
64
  @client.protocol_version = 'HTTP/0.9'
65
- str = ""
65
+ str = "".dup
66
66
  @client.debug_dev = str
67
67
  @client.get(serverurl + 'hello')
68
68
  lines = str.split(/(?:\r?\n)+/)
@@ -76,7 +76,7 @@ class TestClient < Test::Unit::TestCase
76
76
 
77
77
  def test_protocol_version_http10
78
78
  @client.protocol_version = 'HTTP/1.0'
79
- str = ""
79
+ str = "".dup
80
80
  @client.debug_dev = str
81
81
  @client.get(serverurl + 'hello')
82
82
  lines = str.split(/(?:\r?\n)+/)
@@ -88,7 +88,7 @@ class TestClient < Test::Unit::TestCase
88
88
  end
89
89
 
90
90
  def test_protocol_version_http11
91
- str = ""
91
+ str = "".dup
92
92
  @client.debug_dev = str
93
93
  @client.get(serverurl)
94
94
  lines = str.split(/(?:\r?\n)+/)
@@ -97,7 +97,7 @@ class TestClient < Test::Unit::TestCase
97
97
  assert_equal("GET / HTTP/1.1", lines[3])
98
98
  assert_equal("Host: localhost:#{serverport}", lines[7])
99
99
  @client.protocol_version = 'HTTP/1.1'
100
- str = ""
100
+ str = "".dup
101
101
  @client.debug_dev = str
102
102
  @client.get(serverurl)
103
103
  lines = str.split(/(?:\r?\n)+/)
@@ -105,7 +105,7 @@ class TestClient < Test::Unit::TestCase
105
105
  assert_equal("! CONNECTION ESTABLISHED", lines[2])
106
106
  assert_equal("GET / HTTP/1.1", lines[3])
107
107
  @client.protocol_version = 'HTTP/1.0'
108
- str = ""
108
+ str = "".dup
109
109
  @client.debug_dev = str
110
110
  @client.get(serverurl)
111
111
  lines = str.split(/(?:\r?\n)+/)
@@ -130,12 +130,12 @@ class TestClient < Test::Unit::TestCase
130
130
  @client.proxy = uri
131
131
  assert_equal(uri, @client.proxy)
132
132
  #
133
- @proxyio.string = ""
133
+ @proxyio.truncate(0)
134
134
  @client.proxy = nil
135
135
  assert_equal(200, @client.head(serverurl).status)
136
136
  assert(@proxyio.string.empty?)
137
137
  #
138
- @proxyio.string = ""
138
+ @proxyio.truncate(0)
139
139
  @client.proxy = proxyurl
140
140
  assert_equal(200, @client.head(serverurl).status)
141
141
  assert(!@proxyio.string.empty?)
@@ -143,7 +143,7 @@ class TestClient < Test::Unit::TestCase
143
143
  end
144
144
 
145
145
  def test_noproxy_for_localhost
146
- @proxyio.string = ""
146
+ @proxyio.truncate(0)
147
147
  @client.proxy = proxyurl
148
148
  assert_equal(200, @client.head(serverurl).status)
149
149
  assert(@proxyio.string.empty?)
@@ -154,36 +154,36 @@ class TestClient < Test::Unit::TestCase
154
154
  escape_noproxy do
155
155
  # proxy is not set.
156
156
  @client.no_proxy = 'localhost'
157
- @proxyio.string = ""
157
+ @proxyio.truncate(0)
158
158
  @client.proxy = nil
159
159
  assert_equal(200, @client.head(serverurl).status)
160
160
  assert(/accept/ !~ @proxyio.string)
161
161
  #
162
- @proxyio.string = ""
162
+ @proxyio.truncate(0)
163
163
  @client.proxy = proxyurl
164
164
  assert_equal(200, @client.head(serverurl).status)
165
165
  assert(/accept/ !~ @proxyio.string)
166
166
  #
167
167
  @client.no_proxy = 'foobar'
168
- @proxyio.string = ""
168
+ @proxyio.truncate(0)
169
169
  @client.proxy = proxyurl
170
170
  assert_equal(200, @client.head(serverurl).status)
171
171
  assert(/accept/ =~ @proxyio.string)
172
172
  #
173
173
  @client.no_proxy = 'foobar,localhost:baz'
174
- @proxyio.string = ""
174
+ @proxyio.truncate(0)
175
175
  @client.proxy = proxyurl
176
176
  assert_equal(200, @client.head(serverurl).status)
177
177
  assert(/accept/ !~ @proxyio.string)
178
178
  #
179
179
  @client.no_proxy = 'foobar,localhost:443'
180
- @proxyio.string = ""
180
+ @proxyio.truncate(0)
181
181
  @client.proxy = proxyurl
182
182
  assert_equal(200, @client.head(serverurl).status)
183
183
  assert(/accept/ =~ @proxyio.string)
184
184
  #
185
185
  @client.no_proxy = "foobar,localhost:443:localhost:#{serverport},baz"
186
- @proxyio.string = ""
186
+ @proxyio.truncate(0)
187
187
  @client.proxy = proxyurl
188
188
  assert_equal(200, @client.head(serverurl).status)
189
189
  assert(/accept/ !~ @proxyio.string)
@@ -314,14 +314,14 @@ class TestClient < Test::Unit::TestCase
314
314
  end
315
315
 
316
316
  def test_extra_headers
317
- str = ""
317
+ str = "".dup
318
318
  @client.debug_dev = str
319
319
  @client.head(serverurl, nil, {"ABC" => "DEF"})
320
320
  lines = str.split(/(?:\r?\n)+/)
321
321
  assert_equal("= Request", lines[0])
322
322
  assert_match("ABC: DEF", lines[4])
323
323
  #
324
- str = ""
324
+ str = "".dup
325
325
  @client.debug_dev = str
326
326
  @client.get(serverurl, nil, [["ABC", "DEF"], ["ABC", "DEF"]])
327
327
  lines = str.split(/(?:\r?\n)+/)
@@ -331,9 +331,17 @@ class TestClient < Test::Unit::TestCase
331
331
  end
332
332
 
333
333
  def test_timeout
334
- assert_equal(60, @client.connect_timeout)
335
- assert_equal(120, @client.send_timeout)
336
- assert_equal(60, @client.receive_timeout)
334
+ client = HTTPClient.new
335
+ assert_equal(60, client.connect_timeout)
336
+ assert_equal(120, client.send_timeout)
337
+ assert_equal(60, client.receive_timeout)
338
+ #
339
+ client.connect_timeout = 1
340
+ client.send_timeout = 2
341
+ client.receive_timeout = 3
342
+ assert_equal(1, client.connect_timeout)
343
+ assert_equal(2, client.send_timeout)
344
+ assert_equal(3, client.receive_timeout)
337
345
  end
338
346
 
339
347
  def test_connect_timeout
@@ -347,11 +355,13 @@ class TestClient < Test::Unit::TestCase
347
355
  def test_receive_timeout
348
356
  # this test takes 2 sec
349
357
  assert_equal('hello', @client.get_content(serverurl + 'sleep?sec=2'))
358
+ @client.reset_all
350
359
  @client.receive_timeout = 1
351
360
  assert_equal('hello', @client.get_content(serverurl + 'sleep?sec=0'))
352
361
  assert_raise(HTTPClient::ReceiveTimeoutError) do
353
362
  @client.get_content(serverurl + 'sleep?sec=2')
354
363
  end
364
+ @client.reset_all
355
365
  @client.receive_timeout = 3
356
366
  assert_equal('hello', @client.get_content(serverurl + 'sleep?sec=2'))
357
367
  end