requests 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f498fdcb052c62a2936dc7346be84c539cea04ed
4
- data.tar.gz: f6959db0f600cb93d767d7b69239fea389ce94e2
3
+ metadata.gz: 41390f6d44a892d862b7d1ea50926da5770ba58c
4
+ data.tar.gz: 6ee4ee954976e8d56e1d0f9646faa8993c6fe2fb
5
5
  SHA512:
6
- metadata.gz: 7220d08539742522762d74f9a8dd8aee1cf77fb43b60f27914a849843d6cfd094f34d5e7f2f453908d3baa9209401c65718cbc96a73b21d37d3a9c256961c458
7
- data.tar.gz: ca15d8700c19ee2501b816e136c91166d3824ac3b0266a13d4b7c88a9d55db7c79deeb922e4ff163f86b6f58f02ff7a7742b02dca75d4d8316ea392350388a8e
6
+ metadata.gz: 217e21d6a5372943c548434d2c4d8684760083a152eefdceff959d97b42857de3d261a11fd3ef04a34e4e43315861f453ec63dd1f16552c7e98b1ace0584cab0
7
+ data.tar.gz: de74c5f4c50bcc593247bba8dd412df9afbb267a8d8ee0d2c4dfe8ebd79930839f3ba2cef00e3312ae4cb7efc525f65450bd2a9bd87c78304749d9ec809cade4
@@ -21,7 +21,9 @@ module Requests
21
21
  headers: {},
22
22
  data: nil,
23
23
  params: nil,
24
- auth: nil)
24
+ auth: nil,
25
+ proxy: nil,
26
+ options: {})
25
27
 
26
28
  uri = URI.parse(url)
27
29
  uri.query = encode_www_form(params) if params
@@ -30,7 +32,8 @@ module Requests
30
32
 
31
33
  basic_auth(headers, *auth) if auth
32
34
 
33
- response = Net::HTTP.start(uri.host, uri.port, opts(uri)) do |http|
35
+ proxy = proxy.to_h.values_at(:host, :port, :user, :password)
36
+ response = Net::HTTP.start(uri.host, uri.port, *proxy, opts(uri, options)) do |http|
34
37
  http.send_request(method, uri, body, headers)
35
38
  end
36
39
 
@@ -46,11 +49,13 @@ private
46
49
  URI.encode_www_form(params)
47
50
  end
48
51
 
49
- def self.opts(uri)
52
+ def self.opts(uri, options)
50
53
  if uri.scheme == 'https'
51
54
  { use_ssl: true,
52
55
  verify_mode: OpenSSL::SSL::VERIFY_PEER,
53
- ca_file: CA_FILE
56
+ ca_file: CA_FILE,
57
+ read_timeout: options[:read_timeout],
58
+ open_timeout: options[:open_timeout],
54
59
  }
55
60
  end
56
61
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "requests"
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
  s.summary = "Requests: HTTP for Humans (Ruby port)"
7
7
  s.description = "Because Requests for Python is awesome"
8
8
  s.authors = ["Cyril David"]
@@ -0,0 +1,32 @@
1
+ require 'requests/sugar'
2
+ require 'webrick'
3
+ require 'webrick/httpproxy'
4
+ require 'thread'
5
+ require 'logger'
6
+
7
+ port = ENV.fetch("PROXY_PORT", 8000)
8
+
9
+ setup do
10
+ WEBrick::HTTPProxyServer.new(
11
+ ServerName: "0.0.0.0",
12
+ Port: port,
13
+ Logger: Logger.new("/dev/null"),
14
+ AccessLog: []
15
+ )
16
+ end
17
+
18
+ test 'request via proxy' do |proxy|
19
+ Thread.new { proxy.start }
20
+
21
+ r = Requests.get('http://httpbin.org/get', params: { foo: 'bar' }, proxy: {
22
+ host: '0.0.0.0', port: port
23
+ })
24
+
25
+ assert_equal 200, r.status
26
+ assert_equal ['application/json'], r.headers['content-type']
27
+ assert(r.json['args'] && r.json['args']['foo'] == 'bar')
28
+
29
+ assert_equal ["1.1 vegur, 1.1 0.0.0.0:#{port}"], r.headers['via']
30
+
31
+ proxy.shutdown
32
+ end
@@ -57,3 +57,37 @@ test 'Error' do
57
57
  assert_equal Net::HTTPNotFound, e.response.class
58
58
  end
59
59
  end
60
+
61
+ test 'read timeout' do
62
+ begin
63
+ Requests.get('http://httpbin.org:10000', options: { read_timeout: 1 })
64
+ rescue => err
65
+ assert err.kind_of?(Errno::ECONNREFUSED)
66
+ end
67
+ end
68
+
69
+ test 'read timeout not failing' do
70
+ begin
71
+ Requests.get('http://httpbin.org/get', options: { read_timeout: 30 })
72
+ rescue => err
73
+ flunk(err)
74
+ end
75
+ end
76
+
77
+ test 'open timeout' do
78
+ begin
79
+ Requests.get('http://httpbin.org:10000', options: { open_timeout: 1 })
80
+ rescue => err
81
+ assert err.kind_of?(Errno::ECONNREFUSED)
82
+ else
83
+ flunk("expected exception")
84
+ end
85
+ end
86
+
87
+ test 'open timeout not failing' do
88
+ begin
89
+ Requests.get('http://httpbin.org/get', options: { open_timeout: 30 })
90
+ rescue => err
91
+ flunk(err)
92
+ end
93
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: requests
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-03 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
@@ -37,6 +37,7 @@ files:
37
37
  - lib/requests/sugar.rb
38
38
  - makefile
39
39
  - requests.gemspec
40
+ - tests/proxy_test.rb
40
41
  - tests/requests_test.rb
41
42
  - tests/ssl_test.rb
42
43
  homepage: http://github.com/cyx/requests
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  version: '0'
60
61
  requirements: []
61
62
  rubyforge_project:
62
- rubygems_version: 2.2.2
63
+ rubygems_version: 2.5.1
63
64
  signing_key:
64
65
  specification_version: 4
65
66
  summary: 'Requests: HTTP for Humans (Ruby port)'