faraday 0.8.11 → 0.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +6 -0
- data/CONTRIBUTING.md +36 -0
- data/Gemfile +7 -6
- data/LICENSE.md +1 -1
- data/README.md +38 -51
- data/Rakefile +2 -18
- data/faraday.gemspec +34 -0
- data/lib/faraday.rb +181 -67
- data/lib/faraday/adapter.rb +19 -34
- data/lib/faraday/adapter/em_http.rb +24 -10
- data/lib/faraday/adapter/em_synchrony.rb +1 -15
- data/lib/faraday/adapter/excon.rb +6 -12
- data/lib/faraday/adapter/httpclient.rb +92 -0
- data/lib/faraday/adapter/net_http.rb +2 -3
- data/lib/faraday/adapter/net_http_persistent.rb +3 -15
- data/lib/faraday/adapter/patron.rb +13 -21
- data/lib/faraday/adapter/rack.rb +0 -2
- data/lib/faraday/adapter/test.rb +35 -36
- data/lib/faraday/adapter/typhoeus.rb +10 -12
- data/lib/faraday/autoload.rb +87 -0
- data/lib/faraday/connection.rb +196 -99
- data/lib/faraday/error.rb +33 -33
- data/lib/faraday/options.rb +215 -0
- data/lib/faraday/parameters.rb +193 -0
- data/lib/faraday/{builder.rb → rack_builder.rb} +78 -21
- data/lib/faraday/request.rb +12 -25
- data/lib/faraday/request/authorization.rb +3 -3
- data/lib/faraday/request/basic_authentication.rb +1 -1
- data/lib/faraday/request/instrumentation.rb +38 -0
- data/lib/faraday/request/multipart.rb +10 -9
- data/lib/faraday/request/retry.rb +70 -6
- data/lib/faraday/request/token_authentication.rb +2 -2
- data/lib/faraday/request/url_encoded.rb +7 -6
- data/lib/faraday/response.rb +17 -22
- data/lib/faraday/response/logger.rb +4 -4
- data/lib/faraday/response/raise_error.rb +4 -5
- data/lib/faraday/utils.rb +54 -67
- data/script/console +7 -0
- data/script/release +6 -3
- data/script/server +3 -1
- data/script/test +7 -33
- data/test/adapters/em_http_test.rb +6 -1
- data/test/adapters/em_synchrony_test.rb +7 -1
- data/test/adapters/excon_test.rb +0 -7
- data/test/adapters/httpclient_test.rb +16 -0
- data/test/adapters/integration.rb +8 -39
- data/test/adapters/logger_test.rb +1 -1
- data/test/adapters/net_http_test.rb +0 -31
- data/test/adapters/patron_test.rb +1 -1
- data/test/adapters/rack_test.rb +0 -5
- data/test/adapters/test_middleware_test.rb +19 -4
- data/test/adapters/typhoeus_test.rb +20 -3
- data/test/authentication_middleware_test.rb +7 -7
- data/test/connection_test.rb +52 -75
- data/test/env_test.rb +33 -24
- data/test/helper.rb +15 -13
- data/test/live_server.rb +10 -4
- data/test/middleware/instrumentation_test.rb +75 -0
- data/test/middleware/retry_test.rb +44 -38
- data/test/middleware_stack_test.rb +12 -11
- data/test/options_test.rb +126 -0
- data/test/request_middleware_test.rb +17 -7
- data/test/response_middleware_test.rb +2 -4
- data/test/strawberry.rb +2 -0
- metadata +82 -28
- checksums.yaml +0 -7
- data/script/proxy-server +0 -41
- data/test/multibyte.txt +0 -1
- data/test/parameters_test.rb +0 -24
- data/test/utils_test.rb +0 -30
@@ -0,0 +1,126 @@
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
|
+
|
3
|
+
class OptionsTest < Faraday::TestCase
|
4
|
+
class SubOptions < Faraday::Options.new(:sub); end
|
5
|
+
class Options < Faraday::Options.new(:a, :b, :c)
|
6
|
+
options :c => SubOptions
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_request_proxy_setter
|
10
|
+
options = Faraday::RequestOptions.new
|
11
|
+
assert_nil options.proxy
|
12
|
+
|
13
|
+
assert_raises NoMethodError do
|
14
|
+
options[:proxy] = {:booya => 1}
|
15
|
+
end
|
16
|
+
|
17
|
+
options[:proxy] = {:user => 'user'}
|
18
|
+
assert_kind_of Faraday::ProxyOptions, options.proxy
|
19
|
+
assert_equal 'user', options.proxy.user
|
20
|
+
|
21
|
+
options.proxy = nil
|
22
|
+
assert_nil options.proxy
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_proxy_options_from_string
|
26
|
+
options = Faraday::ProxyOptions.from 'http://user:pass@example.org'
|
27
|
+
assert_equal 'user', options.user
|
28
|
+
assert_equal 'pass', options.password
|
29
|
+
assert_kind_of URI, options.uri
|
30
|
+
assert_equal '', options.path
|
31
|
+
assert_equal 80, options.port
|
32
|
+
assert_equal 'example.org', options.host
|
33
|
+
assert_equal 'http', options.scheme
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_from_options
|
37
|
+
options = Options.new 1
|
38
|
+
|
39
|
+
value = Options.from(options)
|
40
|
+
assert_equal 1, value.a
|
41
|
+
assert_nil value.b
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_from_options_with_sub_object
|
45
|
+
sub = SubOptions.new 1
|
46
|
+
options = Options.from :a => 1, :c => sub
|
47
|
+
assert_kind_of Options, options
|
48
|
+
assert_equal 1, options.a
|
49
|
+
assert_nil options.b
|
50
|
+
assert_kind_of SubOptions, options.c
|
51
|
+
assert_equal 1, options.c.sub
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_from_hash
|
55
|
+
options = Options.from :a => 1
|
56
|
+
assert_kind_of Options, options
|
57
|
+
assert_equal 1, options.a
|
58
|
+
assert_nil options.b
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_from_hash_with_sub_object
|
62
|
+
options = Options.from :a => 1, :c => {:sub => 1}
|
63
|
+
assert_kind_of Options, options
|
64
|
+
assert_equal 1, options.a
|
65
|
+
assert_nil options.b
|
66
|
+
assert_kind_of SubOptions, options.c
|
67
|
+
assert_equal 1, options.c.sub
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_from_deep_hash
|
71
|
+
hash = {:b => 1}
|
72
|
+
options = Options.from :a => hash
|
73
|
+
assert_equal 1, options.a[:b]
|
74
|
+
|
75
|
+
hash[:b] = 2
|
76
|
+
assert_equal 1, options.a[:b]
|
77
|
+
|
78
|
+
options.a[:b] = 3
|
79
|
+
assert_equal 2, hash[:b]
|
80
|
+
assert_equal 3, options.a[:b]
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_from_nil
|
84
|
+
options = Options.from(nil)
|
85
|
+
assert_kind_of Options, options
|
86
|
+
assert_nil options.a
|
87
|
+
assert_nil options.b
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_invalid_key
|
91
|
+
assert_raises NoMethodError do
|
92
|
+
Options.from :invalid => 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_update
|
97
|
+
options = Options.new 1
|
98
|
+
assert_equal 1, options.a
|
99
|
+
assert_nil options.b
|
100
|
+
|
101
|
+
updated = options.update :a => 2, :b => 3
|
102
|
+
assert_equal 2, options.a
|
103
|
+
assert_equal 3, options.b
|
104
|
+
assert_equal options, updated
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_delete
|
108
|
+
options = Options.new 1
|
109
|
+
assert_equal 1, options.a
|
110
|
+
assert_equal 1, options.delete(:a)
|
111
|
+
assert_nil options.a
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_merge
|
115
|
+
options = Options.new 1
|
116
|
+
assert_equal 1, options.a
|
117
|
+
assert_nil options.b
|
118
|
+
|
119
|
+
dup = options.merge :a => 2, :b => 3
|
120
|
+
assert_equal 2, dup.a
|
121
|
+
assert_equal 3, dup.b
|
122
|
+
assert_equal 1, options.a
|
123
|
+
assert_nil options.b
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.expand_path(
|
2
|
+
require File.expand_path('../helper', __FILE__)
|
3
3
|
|
4
4
|
Faraday::CompositeReadIO.class_eval { attr_reader :ios }
|
5
5
|
|
@@ -62,12 +62,22 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
62
62
|
assert_equal expected, Faraday::Utils.parse_nested_query(response.body)
|
63
63
|
end
|
64
64
|
|
65
|
+
def test_url_encoded_non_nested
|
66
|
+
response = @conn.post('/echo', { :dimensions => ['date', 'location']}) do |req|
|
67
|
+
req.options.params_encoder = Faraday::FlatParamsEncoder
|
68
|
+
end
|
69
|
+
assert_equal 'application/x-www-form-urlencoded', response.headers['Content-Type']
|
70
|
+
expected = { 'dimensions' => ['date', 'location'] }
|
71
|
+
assert_equal expected, Faraday::Utils.parse_query(response.body)
|
72
|
+
assert_equal 'dimensions=date&dimensions=location', response.body
|
73
|
+
end
|
74
|
+
|
65
75
|
def test_url_encoded_unicode
|
66
76
|
err = capture_warnings {
|
67
77
|
response = @conn.post('/echo', {:str => "eé cç aã aâ"})
|
68
78
|
assert_equal "str=e%C3%A9+c%C3%A7+a%C3%A3+a%C3%A2", response.body
|
69
79
|
}
|
70
|
-
assert err.empty
|
80
|
+
assert err.empty?
|
71
81
|
end
|
72
82
|
|
73
83
|
def test_url_encoded_unicode_with_kcode_set
|
@@ -76,7 +86,7 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
76
86
|
response = @conn.post('/echo', {:str => "eé cç aã aâ"})
|
77
87
|
assert_equal "str=e%C3%A9+c%C3%A7+a%C3%A3+a%C3%A2", response.body
|
78
88
|
}
|
79
|
-
assert err.empty
|
89
|
+
assert err.empty?
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
@@ -96,7 +106,7 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
96
106
|
response = @conn.post('/echo', payload)
|
97
107
|
|
98
108
|
assert_kind_of Faraday::CompositeReadIO, response.body
|
99
|
-
assert_equal "multipart/form-data;
|
109
|
+
assert_equal "multipart/form-data;boundary=%s" % Faraday::Request::Multipart::DEFAULT_BOUNDARY,
|
100
110
|
response.headers['Content-Type']
|
101
111
|
|
102
112
|
response.body.send(:ios).map{|io| io.read}.each do |io|
|
@@ -106,7 +116,7 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
106
116
|
end
|
107
117
|
assert_equal [], regexes
|
108
118
|
end
|
109
|
-
|
119
|
+
|
110
120
|
def test_multipart_with_arrays
|
111
121
|
# assume params are out of order
|
112
122
|
regexes = [
|
@@ -118,7 +128,7 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
118
128
|
response = @conn.post('/echo', payload)
|
119
129
|
|
120
130
|
assert_kind_of Faraday::CompositeReadIO, response.body
|
121
|
-
assert_equal "multipart/form-data;
|
131
|
+
assert_equal "multipart/form-data;boundary=%s" % Faraday::Request::Multipart::DEFAULT_BOUNDARY,
|
122
132
|
response.headers['Content-Type']
|
123
133
|
|
124
134
|
response.body.send(:ios).map{|io| io.read}.each do |io|
|
@@ -128,5 +138,5 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
128
138
|
end
|
129
139
|
assert_equal [], regexes
|
130
140
|
end
|
131
|
-
|
141
|
+
|
132
142
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
2
2
|
|
3
3
|
class ResponseMiddlewareTest < Faraday::TestCase
|
4
4
|
def setup
|
@@ -19,9 +19,7 @@ class ResponseMiddlewareTest < Faraday::TestCase
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_success
|
22
|
-
|
23
|
-
@conn.get('ok')
|
24
|
-
end
|
22
|
+
assert @conn.get('ok')
|
25
23
|
end
|
26
24
|
|
27
25
|
def test_raises_not_found
|
data/test/strawberry.rb
ADDED
metadata
CHANGED
@@ -1,77 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0.rc1
|
5
|
+
prerelease: 6
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Rick Olson
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2013-05-08 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: multipart-post
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
21
|
+
version: '1.1'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
29
|
+
version: '1.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.0'
|
27
46
|
description:
|
28
47
|
email: technoweenie@gmail.com
|
29
48
|
executables: []
|
30
49
|
extensions: []
|
31
50
|
extra_rdoc_files: []
|
32
51
|
files:
|
52
|
+
- .document
|
53
|
+
- CONTRIBUTING.md
|
33
54
|
- Gemfile
|
34
55
|
- LICENSE.md
|
35
56
|
- README.md
|
36
57
|
- Rakefile
|
37
|
-
-
|
38
|
-
- lib/faraday/adapter.rb
|
58
|
+
- faraday.gemspec
|
39
59
|
- lib/faraday/adapter/em_http.rb
|
40
|
-
- lib/faraday/adapter/em_synchrony.rb
|
41
60
|
- lib/faraday/adapter/em_synchrony/parallel_manager.rb
|
61
|
+
- lib/faraday/adapter/em_synchrony.rb
|
42
62
|
- lib/faraday/adapter/excon.rb
|
63
|
+
- lib/faraday/adapter/httpclient.rb
|
43
64
|
- lib/faraday/adapter/net_http.rb
|
44
65
|
- lib/faraday/adapter/net_http_persistent.rb
|
45
66
|
- lib/faraday/adapter/patron.rb
|
46
67
|
- lib/faraday/adapter/rack.rb
|
47
68
|
- lib/faraday/adapter/test.rb
|
48
69
|
- lib/faraday/adapter/typhoeus.rb
|
49
|
-
- lib/faraday/
|
70
|
+
- lib/faraday/adapter.rb
|
71
|
+
- lib/faraday/autoload.rb
|
50
72
|
- lib/faraday/connection.rb
|
51
73
|
- lib/faraday/error.rb
|
52
74
|
- lib/faraday/middleware.rb
|
53
|
-
- lib/faraday/
|
75
|
+
- lib/faraday/options.rb
|
76
|
+
- lib/faraday/parameters.rb
|
77
|
+
- lib/faraday/rack_builder.rb
|
54
78
|
- lib/faraday/request/authorization.rb
|
55
79
|
- lib/faraday/request/basic_authentication.rb
|
80
|
+
- lib/faraday/request/instrumentation.rb
|
56
81
|
- lib/faraday/request/multipart.rb
|
57
82
|
- lib/faraday/request/retry.rb
|
58
83
|
- lib/faraday/request/token_authentication.rb
|
59
84
|
- lib/faraday/request/url_encoded.rb
|
60
|
-
- lib/faraday/
|
85
|
+
- lib/faraday/request.rb
|
61
86
|
- lib/faraday/response/logger.rb
|
62
87
|
- lib/faraday/response/raise_error.rb
|
88
|
+
- lib/faraday/response.rb
|
63
89
|
- lib/faraday/upload_io.rb
|
64
90
|
- lib/faraday/utils.rb
|
65
|
-
-
|
66
|
-
- script/package
|
67
|
-
- script/proxy-server
|
68
|
-
- script/release
|
69
|
-
- script/server
|
70
|
-
- script/test
|
91
|
+
- lib/faraday.rb
|
71
92
|
- test/adapters/default_test.rb
|
72
93
|
- test/adapters/em_http_test.rb
|
73
94
|
- test/adapters/em_synchrony_test.rb
|
74
95
|
- test/adapters/excon_test.rb
|
96
|
+
- test/adapters/httpclient_test.rb
|
75
97
|
- test/adapters/integration.rb
|
76
98
|
- test/adapters/logger_test.rb
|
77
99
|
- test/adapters/net_http_persistent_test.rb
|
@@ -86,36 +108,68 @@ files:
|
|
86
108
|
- test/env_test.rb
|
87
109
|
- test/helper.rb
|
88
110
|
- test/live_server.rb
|
111
|
+
- test/middleware/instrumentation_test.rb
|
89
112
|
- test/middleware/retry_test.rb
|
90
113
|
- test/middleware_stack_test.rb
|
91
|
-
- test/
|
92
|
-
- test/parameters_test.rb
|
114
|
+
- test/options_test.rb
|
93
115
|
- test/request_middleware_test.rb
|
94
116
|
- test/response_middleware_test.rb
|
95
|
-
- test/
|
117
|
+
- test/strawberry.rb
|
118
|
+
- script/console
|
119
|
+
- script/generate_certs
|
120
|
+
- script/package
|
121
|
+
- script/release
|
122
|
+
- script/server
|
123
|
+
- script/test
|
96
124
|
homepage: https://github.com/lostisland/faraday
|
97
125
|
licenses:
|
98
126
|
- MIT
|
99
|
-
metadata: {}
|
100
127
|
post_install_message:
|
101
128
|
rdoc_options: []
|
102
129
|
require_paths:
|
103
130
|
- lib
|
104
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
105
133
|
requirements:
|
106
|
-
- -
|
134
|
+
- - ! '>='
|
107
135
|
- !ruby/object:Gem::Version
|
108
136
|
version: '0'
|
109
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
110
139
|
requirements:
|
111
|
-
- -
|
140
|
+
- - ! '>'
|
112
141
|
- !ruby/object:Gem::Version
|
113
|
-
version: 1.3.
|
142
|
+
version: 1.3.1
|
114
143
|
requirements: []
|
115
144
|
rubyforge_project:
|
116
|
-
rubygems_version:
|
145
|
+
rubygems_version: 1.8.23
|
117
146
|
signing_key:
|
118
147
|
specification_version: 2
|
119
148
|
summary: HTTP/REST API client library.
|
120
|
-
test_files:
|
121
|
-
|
149
|
+
test_files:
|
150
|
+
- test/adapters/default_test.rb
|
151
|
+
- test/adapters/em_http_test.rb
|
152
|
+
- test/adapters/em_synchrony_test.rb
|
153
|
+
- test/adapters/excon_test.rb
|
154
|
+
- test/adapters/httpclient_test.rb
|
155
|
+
- test/adapters/integration.rb
|
156
|
+
- test/adapters/logger_test.rb
|
157
|
+
- test/adapters/net_http_persistent_test.rb
|
158
|
+
- test/adapters/net_http_test.rb
|
159
|
+
- test/adapters/patron_test.rb
|
160
|
+
- test/adapters/rack_test.rb
|
161
|
+
- test/adapters/test_middleware_test.rb
|
162
|
+
- test/adapters/typhoeus_test.rb
|
163
|
+
- test/authentication_middleware_test.rb
|
164
|
+
- test/composite_read_io_test.rb
|
165
|
+
- test/connection_test.rb
|
166
|
+
- test/env_test.rb
|
167
|
+
- test/helper.rb
|
168
|
+
- test/live_server.rb
|
169
|
+
- test/middleware/instrumentation_test.rb
|
170
|
+
- test/middleware/retry_test.rb
|
171
|
+
- test/middleware_stack_test.rb
|
172
|
+
- test/options_test.rb
|
173
|
+
- test/request_middleware_test.rb
|
174
|
+
- test/response_middleware_test.rb
|
175
|
+
- test/strawberry.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 431792ff21fb498eb658855f87503d2081869616
|
4
|
-
data.tar.gz: c6b3a7f9c1a9f7a4a60eff2236b882dbd812eab4
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 8855727969169984a104ba02c2ed27b4a86fb7d3a698fe6f5932c4858cb5e4f5eba9251d3742cb8d999b654f89ff2d073228738998f3199ae104e9e9883bd031
|
7
|
-
data.tar.gz: eda459cc1abe00450f0d48dab3b069544dd414001faf9be231e2215fa81efced7496a99a2baa6502f1d7bbe162f6b41f415cdef1cd9ce935a9de8752749997a3
|
data/script/proxy-server
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Usage: script/proxy-server [-p PORT] [-u USER:PASSWORD]
|
3
|
-
require 'webrick'
|
4
|
-
require 'webrick/httpproxy'
|
5
|
-
|
6
|
-
port = 4001
|
7
|
-
|
8
|
-
if found = ARGV.index('-p')
|
9
|
-
port = ARGV[found + 1].to_i
|
10
|
-
end
|
11
|
-
if found = ARGV.index('-u')
|
12
|
-
username, password = ARGV[found + 1].split(':', 2)
|
13
|
-
end
|
14
|
-
|
15
|
-
match_credentials = lambda { |credentials|
|
16
|
-
got_username, got_password = credentials.to_s.unpack("m*")[0].split(":", 2)
|
17
|
-
got_username == username && got_password == password
|
18
|
-
}
|
19
|
-
|
20
|
-
log_io = $stdout
|
21
|
-
log_io.sync = true
|
22
|
-
|
23
|
-
webrick_opts = {
|
24
|
-
:Port => port, :Logger => WEBrick::Log::new(log_io),
|
25
|
-
:AccessLog => [[log_io, "[%{X-Faraday-Adapter}i] %m %U -> %s %b"]],
|
26
|
-
:ProxyAuthProc => lambda { |req, res|
|
27
|
-
if username
|
28
|
-
type, credentials = req.header['proxy-authorization'].first.to_s.split(/\s+/, 2)
|
29
|
-
unless "Basic" == type && match_credentials.call(credentials)
|
30
|
-
raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
|
31
|
-
end
|
32
|
-
end
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
proxy = WEBrick::HTTPProxyServer.new(webrick_opts)
|
37
|
-
|
38
|
-
trap(:TERM) { proxy.shutdown }
|
39
|
-
trap(:INT) { proxy.shutdown }
|
40
|
-
|
41
|
-
proxy.start
|