faraday 0.9.1 → 0.9.2
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/LICENSE.md +1 -1
- data/README.md +41 -16
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter/em_synchrony.rb +8 -0
- data/lib/faraday/adapter/excon.rb +1 -0
- data/lib/faraday/adapter/httpclient.rb +14 -3
- data/lib/faraday/adapter/net_http.rb +2 -2
- data/lib/faraday/adapter/net_http_persistent.rb +2 -1
- data/lib/faraday/adapter/patron.rb +8 -2
- data/lib/faraday/connection.rb +8 -3
- data/lib/faraday/options.rb +9 -0
- data/lib/faraday/parameters.rb +54 -38
- data/lib/faraday/rack_builder.rb +3 -2
- data/lib/faraday/request/retry.rb +9 -3
- data/lib/faraday/response.rb +2 -2
- data/lib/faraday/utils.rb +13 -1
- metadata +61 -124
- checksums.yaml +0 -7
- data/.document +0 -6
- data/CHANGELOG.md +0 -20
- data/CONTRIBUTING.md +0 -36
- data/Gemfile +0 -25
- data/Rakefile +0 -71
- data/faraday.gemspec +0 -34
- data/script/cached-bundle +0 -46
- data/script/console +0 -7
- data/script/generate_certs +0 -42
- data/script/package +0 -7
- data/script/proxy-server +0 -42
- data/script/release +0 -17
- data/script/s3-put +0 -71
- data/script/server +0 -36
- data/script/test +0 -172
- data/test/adapters/default_test.rb +0 -14
- data/test/adapters/em_http_test.rb +0 -20
- data/test/adapters/em_synchrony_test.rb +0 -20
- data/test/adapters/excon_test.rb +0 -20
- data/test/adapters/httpclient_test.rb +0 -21
- data/test/adapters/integration.rb +0 -254
- data/test/adapters/logger_test.rb +0 -82
- data/test/adapters/net_http_persistent_test.rb +0 -20
- data/test/adapters/net_http_test.rb +0 -14
- data/test/adapters/patron_test.rb +0 -20
- data/test/adapters/rack_test.rb +0 -31
- data/test/adapters/test_middleware_test.rb +0 -114
- data/test/adapters/typhoeus_test.rb +0 -28
- data/test/authentication_middleware_test.rb +0 -65
- data/test/composite_read_io_test.rb +0 -111
- data/test/connection_test.rb +0 -522
- data/test/env_test.rb +0 -218
- data/test/helper.rb +0 -81
- data/test/live_server.rb +0 -67
- data/test/middleware/instrumentation_test.rb +0 -88
- data/test/middleware/retry_test.rb +0 -177
- data/test/middleware_stack_test.rb +0 -173
- data/test/multibyte.txt +0 -1
- data/test/options_test.rb +0 -252
- data/test/parameters_test.rb +0 -64
- data/test/request_middleware_test.rb +0 -142
- data/test/response_middleware_test.rb +0 -72
- data/test/strawberry.rb +0 -2
- data/test/utils_test.rb +0 -58
data/script/cached-bundle
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
# Usage: cached-bundle install --deployment
|
3
|
-
#
|
4
|
-
# After running `bundle`, caches the `./bundle` directory to S3.
|
5
|
-
# On the next run, restores the cached directory before running `bundle`.
|
6
|
-
# When `Gemfile` changes, the cache gets rebuilt.
|
7
|
-
#
|
8
|
-
# Requirements:
|
9
|
-
# - Gemfile
|
10
|
-
# - TRAVIS_REPO_SLUG
|
11
|
-
# - TRAVIS_RUBY_VERSION
|
12
|
-
# - AMAZON_S3_BUCKET
|
13
|
-
# - script/s3-put
|
14
|
-
# - bundle
|
15
|
-
# - curl
|
16
|
-
#
|
17
|
-
# Author: Mislav Marohnić
|
18
|
-
|
19
|
-
set -e
|
20
|
-
|
21
|
-
compute_md5() {
|
22
|
-
local output="$(openssl md5)"
|
23
|
-
echo "${output##* }"
|
24
|
-
}
|
25
|
-
|
26
|
-
download() {
|
27
|
-
curl --tcp-nodelay -qsfL "$1" -o "$2"
|
28
|
-
}
|
29
|
-
|
30
|
-
bundle_path="bundle"
|
31
|
-
gemfile_hash="$(compute_md5 <"${BUNDLE_GEMFILE:-Gemfile}")"
|
32
|
-
cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz"
|
33
|
-
fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}"
|
34
|
-
|
35
|
-
if download "$fetch_url" "$cache_name"; then
|
36
|
-
echo "Reusing cached bundle ${cache_name}"
|
37
|
-
tar xzf "$cache_name"
|
38
|
-
fi
|
39
|
-
|
40
|
-
bundle "$@"
|
41
|
-
|
42
|
-
if [ ! -f "$cache_name" ] && [ -n "$AMAZON_SECRET_ACCESS_KEY" ]; then
|
43
|
-
echo "Caching \`${bundle_path}' to S3"
|
44
|
-
tar czf "$cache_name" "$bundle_path"
|
45
|
-
script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}"
|
46
|
-
fi
|
data/script/console
DELETED
data/script/generate_certs
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Usage: generate_certs
|
3
|
-
# Generate test certs for testing Faraday with SSL
|
4
|
-
|
5
|
-
require 'openssl'
|
6
|
-
require 'fileutils'
|
7
|
-
|
8
|
-
$shell = ARGV.include? '-s'
|
9
|
-
|
10
|
-
# Adapted from WEBrick::Utils. Skips cert extensions so it
|
11
|
-
# can be used as a CA bundle
|
12
|
-
def create_self_signed_cert(bits, cn, comment)
|
13
|
-
rsa = OpenSSL::PKey::RSA.new(bits)
|
14
|
-
cert = OpenSSL::X509::Certificate.new
|
15
|
-
cert.version = 2
|
16
|
-
cert.serial = 1
|
17
|
-
name = OpenSSL::X509::Name.new(cn)
|
18
|
-
cert.subject = name
|
19
|
-
cert.issuer = name
|
20
|
-
cert.not_before = Time.now
|
21
|
-
cert.not_after = Time.now + (365*24*60*60)
|
22
|
-
cert.public_key = rsa.public_key
|
23
|
-
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
|
24
|
-
return [cert, rsa]
|
25
|
-
end
|
26
|
-
|
27
|
-
def write(file, contents, env_var)
|
28
|
-
FileUtils.mkdir_p(File.dirname(file))
|
29
|
-
File.open(file, 'w') {|f| f.puts(contents) }
|
30
|
-
puts %(export #{env_var}="#{file}") if $shell
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
# One cert / CA for ease of testing when ignoring verification
|
35
|
-
cert, key = create_self_signed_cert(1024, [['CN', 'localhost']], 'Faraday Test CA')
|
36
|
-
write 'tmp/faraday-cert.key', key, 'SSL_KEY'
|
37
|
-
write 'tmp/faraday-cert.crt', cert, 'SSL_FILE'
|
38
|
-
|
39
|
-
# And a second CA to prove that verification can fail
|
40
|
-
cert, key = create_self_signed_cert(1024, [['CN', 'real-ca.com']], 'A different CA')
|
41
|
-
write 'tmp/faraday-different-ca-cert.key', key, 'SSL_KEY_ALT'
|
42
|
-
write 'tmp/faraday-different-ca-cert.crt', cert, 'SSL_FILE_ALT'
|
data/script/package
DELETED
data/script/proxy-server
DELETED
@@ -1,42 +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
|
-
res['proxy-authenticate'] = %{Basic realm="testing"}
|
31
|
-
raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
|
32
|
-
end
|
33
|
-
end
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
proxy = WEBrick::HTTPProxyServer.new(webrick_opts)
|
38
|
-
|
39
|
-
trap(:TERM) { proxy.shutdown }
|
40
|
-
trap(:INT) { proxy.shutdown }
|
41
|
-
|
42
|
-
proxy.start
|
data/script/release
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
# Usage: script/release
|
3
|
-
# Build the package, tag a commit, push it to origin, and then release the
|
4
|
-
# package publicly.
|
5
|
-
|
6
|
-
set -e
|
7
|
-
|
8
|
-
version="$(script/package | grep Version: | awk '{print $2}')"
|
9
|
-
[ -n "$version" ] || exit 1
|
10
|
-
|
11
|
-
git commit --allow-empty -a -m "Release $version"
|
12
|
-
git tag "v$version"
|
13
|
-
git push origin
|
14
|
-
git push origin "v$version"
|
15
|
-
git push legacy
|
16
|
-
git push legacy "v$version"
|
17
|
-
gem push pkg/*-${version}.gem
|
data/script/s3-put
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]
|
3
|
-
#
|
4
|
-
# Uploads a file to the Amazon S3 service.
|
5
|
-
# Outputs the URL for the newly uploaded file.
|
6
|
-
#
|
7
|
-
# Requirements:
|
8
|
-
# - AMAZON_ACCESS_KEY_ID
|
9
|
-
# - AMAZON_SECRET_ACCESS_KEY
|
10
|
-
# - openssl
|
11
|
-
# - curl
|
12
|
-
#
|
13
|
-
# Author: Mislav Marohnić
|
14
|
-
|
15
|
-
set -e
|
16
|
-
|
17
|
-
authorization() {
|
18
|
-
local signature="$(string_to_sign | hmac_sha1 | base64)"
|
19
|
-
echo "AWS ${AMAZON_ACCESS_KEY_ID?}:${signature}"
|
20
|
-
}
|
21
|
-
|
22
|
-
hmac_sha1() {
|
23
|
-
openssl dgst -binary -sha1 -hmac "${AMAZON_SECRET_ACCESS_KEY?}"
|
24
|
-
}
|
25
|
-
|
26
|
-
base64() {
|
27
|
-
openssl enc -base64
|
28
|
-
}
|
29
|
-
|
30
|
-
bin_md5() {
|
31
|
-
openssl dgst -binary -md5
|
32
|
-
}
|
33
|
-
|
34
|
-
string_to_sign() {
|
35
|
-
echo "$http_method"
|
36
|
-
echo "$content_md5"
|
37
|
-
echo "$content_type"
|
38
|
-
echo "$date"
|
39
|
-
echo "x-amz-acl:$acl"
|
40
|
-
printf "/$bucket/$remote_path"
|
41
|
-
}
|
42
|
-
|
43
|
-
date_string() {
|
44
|
-
LC_TIME=C date "+%a, %d %h %Y %T %z"
|
45
|
-
}
|
46
|
-
|
47
|
-
file="$1"
|
48
|
-
bucket="${2%%:*}"
|
49
|
-
remote_path="${2#*:}"
|
50
|
-
content_type="$3"
|
51
|
-
|
52
|
-
if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then
|
53
|
-
remote_path="${file##*/}"
|
54
|
-
fi
|
55
|
-
|
56
|
-
http_method=PUT
|
57
|
-
acl="public-read"
|
58
|
-
content_md5="$(bin_md5 < "$file" | base64)"
|
59
|
-
date="$(date_string)"
|
60
|
-
|
61
|
-
url="https://$bucket.s3.amazonaws.com/$remote_path"
|
62
|
-
|
63
|
-
curl -qsSf -T "$file" \
|
64
|
-
-H "Authorization: $(authorization)" \
|
65
|
-
-H "x-amz-acl: $acl" \
|
66
|
-
-H "Date: $date" \
|
67
|
-
-H "Content-MD5: $content_md5" \
|
68
|
-
-H "Content-Type: $content_type" \
|
69
|
-
"$url"
|
70
|
-
|
71
|
-
echo "$url"
|
data/script/server
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
3
|
-
begin
|
4
|
-
require File.expand_path('../../test/live_server', __FILE__)
|
5
|
-
ensure
|
6
|
-
$VERBOSE = old_verbose
|
7
|
-
end
|
8
|
-
require 'webrick'
|
9
|
-
|
10
|
-
port = 4000
|
11
|
-
if found = ARGV.index('-p')
|
12
|
-
port = ARGV[found + 1].to_i
|
13
|
-
end
|
14
|
-
|
15
|
-
log_io = $stdout
|
16
|
-
log_io.sync = true
|
17
|
-
|
18
|
-
webrick_opts = {
|
19
|
-
:Port => port, :Logger => WEBrick::Log::new(log_io),
|
20
|
-
:AccessLog => [[log_io, "[%{X-Faraday-Adapter}i] %m %U -> %s %b"]]
|
21
|
-
}
|
22
|
-
|
23
|
-
if ENV['SSL_KEY']
|
24
|
-
require 'openssl'
|
25
|
-
require 'webrick/https'
|
26
|
-
webrick_opts.update \
|
27
|
-
:SSLEnable => true,
|
28
|
-
:SSLPrivateKey => OpenSSL::PKey::RSA.new(File.read(ENV['SSL_KEY'])),
|
29
|
-
:SSLCertificate => OpenSSL::X509::Certificate.new(File.read(ENV['SSL_FILE'])),
|
30
|
-
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE
|
31
|
-
end
|
32
|
-
|
33
|
-
Rack::Handler::WEBrick.run(Faraday::LiveServer, webrick_opts) do |server|
|
34
|
-
trap(:INT) { server.stop }
|
35
|
-
trap(:TERM) { server.stop }
|
36
|
-
end
|
data/script/test
DELETED
@@ -1,172 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
# Usage: script/test [file] [adapter]... -- [test/unit options]
|
3
|
-
# Runs the test suite against a local server spawned automatically in a
|
4
|
-
# thread. After tests are done, the server is shut down.
|
5
|
-
#
|
6
|
-
# If filename arguments are given, only those files are run. If arguments given
|
7
|
-
# are not filenames, they are taken as words that filter the list of files to run.
|
8
|
-
#
|
9
|
-
# Examples:
|
10
|
-
#
|
11
|
-
# $ script/test
|
12
|
-
# $ script/test test/env_test.rb
|
13
|
-
# $ script/test excon typhoeus
|
14
|
-
#
|
15
|
-
# # Run only tests matching /ssl/ for the net_http adapter, with SSL enabled.
|
16
|
-
# $ SSL=yes script/test net_http -- -n /ssl/
|
17
|
-
#
|
18
|
-
# # Run against multiple rbenv versions
|
19
|
-
# $ RBENV_VERSIONS="1.9.3-p194 ree-1.8.7-2012.02" script/test
|
20
|
-
set -e
|
21
|
-
|
22
|
-
if [[ "$RUBYOPT" != *"bundler/setup"* ]]; then
|
23
|
-
export RUBYOPT="-rbundler/setup $RUBYOPT"
|
24
|
-
fi
|
25
|
-
|
26
|
-
port=3999
|
27
|
-
proxy_port=3998
|
28
|
-
scheme=http
|
29
|
-
|
30
|
-
if [ "$SSL" = "yes" ]; then
|
31
|
-
scheme=https
|
32
|
-
if [ -z "$SSL_KEY" ] || [ -z "$SSL_FILE" ]; then
|
33
|
-
eval "$(script/generate_certs -s)"
|
34
|
-
fi
|
35
|
-
fi
|
36
|
-
|
37
|
-
find_test_files() {
|
38
|
-
find "$1" -name '*_test.rb'
|
39
|
-
}
|
40
|
-
|
41
|
-
filter_matching() {
|
42
|
-
pattern="$1"
|
43
|
-
shift
|
44
|
-
for line in "$@"; do
|
45
|
-
[[ $line == *"$pattern"* ]] && echo "$line"
|
46
|
-
done
|
47
|
-
}
|
48
|
-
|
49
|
-
start_server() {
|
50
|
-
mkdir -p log
|
51
|
-
script/server -p $port >log/test.log 2>&1 &
|
52
|
-
echo $!
|
53
|
-
}
|
54
|
-
|
55
|
-
start_proxy() {
|
56
|
-
mkdir -p log
|
57
|
-
script/proxy-server -p $proxy_port -u "faraday@test.local:there is cake" >log/proxy.log 2>&1 &
|
58
|
-
echo $!
|
59
|
-
}
|
60
|
-
|
61
|
-
server_started() {
|
62
|
-
lsof -i :${1?} >/dev/null
|
63
|
-
}
|
64
|
-
|
65
|
-
timestamp() {
|
66
|
-
date +%s
|
67
|
-
}
|
68
|
-
|
69
|
-
wait_for_server() {
|
70
|
-
timeout=$(( `timestamp` + $1 ))
|
71
|
-
while true; do
|
72
|
-
if server_started "$2"; then
|
73
|
-
break
|
74
|
-
elif [ `timestamp` -gt "$timeout" ]; then
|
75
|
-
echo "timed out after $1 seconds" >&2
|
76
|
-
return 1
|
77
|
-
fi
|
78
|
-
done
|
79
|
-
}
|
80
|
-
|
81
|
-
filtered=
|
82
|
-
IFS=$'\n' test_files=($(find_test_files "test"))
|
83
|
-
declare -a explicit_files
|
84
|
-
|
85
|
-
# Process filter arguments:
|
86
|
-
# - test filenames as taken as-is
|
87
|
-
# - other words are taken as pattern to match the list of known files against
|
88
|
-
# - arguments after "--" are forwarded to the ruby process
|
89
|
-
while [ $# -gt 0 ]; do
|
90
|
-
arg="$1"
|
91
|
-
shift
|
92
|
-
if [ "$arg" = "--" ]; then
|
93
|
-
break
|
94
|
-
elif [ -f "$arg" ]; then
|
95
|
-
filtered=true
|
96
|
-
explicit_files[${#explicit_files[@]}+1]="$arg"
|
97
|
-
else
|
98
|
-
filtered=true
|
99
|
-
IFS=$'\n' explicit_files=(
|
100
|
-
${explicit_files[@]}
|
101
|
-
$(filter_matching "$arg" "${test_files[@]}" || true)
|
102
|
-
)
|
103
|
-
fi
|
104
|
-
done
|
105
|
-
|
106
|
-
# If there were filter args, replace test files list with the results
|
107
|
-
if [ -n "$filtered" ]; then
|
108
|
-
if [ ${#explicit_files[@]} -eq 0 ]; then
|
109
|
-
echo "Error: no test files match" >&2
|
110
|
-
exit 1
|
111
|
-
else
|
112
|
-
test_files=(${explicit_files[@]})
|
113
|
-
echo running "${test_files[@]}"
|
114
|
-
fi
|
115
|
-
fi
|
116
|
-
|
117
|
-
# If there are any adapter tests, spin up the HTTP server
|
118
|
-
if [ -n "$(filter_matching "adapters" "${test_files[@]}")" ]; then
|
119
|
-
if server_started $port; then
|
120
|
-
echo "aborted: another instance of server running on $port" >&2
|
121
|
-
exit 1
|
122
|
-
fi
|
123
|
-
server_pid=$(start_server)
|
124
|
-
proxy_pid=$(start_proxy)
|
125
|
-
wait_for_server 30 $port || {
|
126
|
-
cat log/test.log
|
127
|
-
kill "$server_pid"
|
128
|
-
kill "$proxy_pid"
|
129
|
-
exit 1
|
130
|
-
}
|
131
|
-
wait_for_server 5 $proxy_port
|
132
|
-
cleanup() {
|
133
|
-
if [ $? -ne 0 ] && [ -n "$TRAVIS" ]; then
|
134
|
-
cat log/test.log
|
135
|
-
fi
|
136
|
-
kill "$server_pid"
|
137
|
-
kill "$proxy_pid"
|
138
|
-
}
|
139
|
-
trap cleanup INT EXIT
|
140
|
-
export LIVE="${scheme}://localhost:${port}"
|
141
|
-
export LIVE_PROXY="http://faraday%40test.local:there%20is%20cake@localhost:${proxy_port}"
|
142
|
-
fi
|
143
|
-
|
144
|
-
warnings="${TMPDIR:-/tmp}/faraday-warnings.$$"
|
145
|
-
|
146
|
-
run_test_files() {
|
147
|
-
# Save warnings on stderr to a separate file
|
148
|
-
RUBYOPT="$RUBYOPT -w" ruby -e 'while f=ARGV.shift and f!="--"; load f; end' "${test_files[@]}" -- "$@" \
|
149
|
-
2> >(tee >(grep 'warning:' >"$warnings") | grep -v 'warning:')
|
150
|
-
}
|
151
|
-
|
152
|
-
check_warnings() {
|
153
|
-
# Display Ruby warnings from this project's source files. Abort if any were found.
|
154
|
-
num="$(grep -F "$PWD" "$warnings" | grep -v "${PWD}/bundle" | sort | uniq -c | sort -rn | tee /dev/stderr | wc -l)"
|
155
|
-
rm -f "$warnings"
|
156
|
-
if [ "$num" -gt 0 ]; then
|
157
|
-
echo "FAILED: this test suite doesn't tolerate Ruby syntax warnings!" >&2
|
158
|
-
exit 1
|
159
|
-
fi
|
160
|
-
}
|
161
|
-
|
162
|
-
if [ -n "$RBENV_VERSIONS" ]; then
|
163
|
-
IFS=' ' versions=($RBENV_VERSIONS)
|
164
|
-
for version in "${versions[@]}"; do
|
165
|
-
echo "[${version}]"
|
166
|
-
RBENV_VERSION="$version" run_test_files "$@"
|
167
|
-
done
|
168
|
-
else
|
169
|
-
run_test_files "$@"
|
170
|
-
fi
|
171
|
-
|
172
|
-
check_warnings
|