httpadapter 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/lib/httpadapter/adapters/mock.rb +43 -0
- data/lib/httpadapter/adapters/net_http.rb +15 -0
- data/lib/httpadapter/version.rb +1 -1
- data/spec/httpadapter/adapters/net_http_request_spec.rb +3 -1
- data/spec/httpadapter/adapters/net_http_transmission_spec.rb +1 -1
- data/tasks/gem.rake +1 -1
- metadata +8 -7
data/CHANGELOG
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Copyright (C) 2010 Google Inc.
|
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
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'httpadapter'
|
16
|
+
|
17
|
+
module HTTPAdapter #:nodoc:
|
18
|
+
##
|
19
|
+
# A simple module for mocking the transmit method on an adapter.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# # Using RSpec, verify that the request being sent includes a user agent.
|
23
|
+
# adapter = HTTPAdapter::MockAdapter.request_adapter do |req, conn|
|
24
|
+
# method, uri, headers, body = req
|
25
|
+
# headers.should be_any { |k, v| k.downcase == 'user-agent' }
|
26
|
+
# end
|
27
|
+
module MockAdapter
|
28
|
+
def self.request_adapter(&block)
|
29
|
+
return Class.new do
|
30
|
+
@@block = block
|
31
|
+
|
32
|
+
def self.transmit(*params)
|
33
|
+
response = @@block.call(*params)
|
34
|
+
if response.respond_to?(:each)
|
35
|
+
return response
|
36
|
+
else
|
37
|
+
return [200, [], ['']]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -114,6 +114,21 @@ module HTTPAdapter #:nodoc:
|
|
114
114
|
store = OpenSSL::X509::Store.new
|
115
115
|
store.set_default_paths
|
116
116
|
http.cert_store = store
|
117
|
+
context = http.instance_variable_get('@ssl_context')
|
118
|
+
if context && context.respond_to?(:tmp_dh_callback) &&
|
119
|
+
context.tmp_dh_callback == nil
|
120
|
+
context.tmp_dh_callback = lambda do |*args|
|
121
|
+
tmp_dh_key_file = File.expand_path(
|
122
|
+
ENV['TMP_DH_KEY_FILE'] || "~/.dhparams.pem"
|
123
|
+
)
|
124
|
+
if File.exists?(tmp_dh_key_file)
|
125
|
+
OpenSSL::PKey::DH.new(File.read(tmp_dh_key_file))
|
126
|
+
else
|
127
|
+
# Slow, fix with `openssl dhparam -out ~/.dhparams.pem 2048`
|
128
|
+
OpenSSL::PKey::DH.new(512)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
117
132
|
end
|
118
133
|
http.start
|
119
134
|
connection = HTTPAdapter::Connection.new(
|
data/lib/httpadapter/version.rb
CHANGED
@@ -322,7 +322,9 @@ describe HTTPAdapter::NetHTTPRequestAdapter,
|
|
322
322
|
end
|
323
323
|
|
324
324
|
it 'should convert the body properly' do
|
325
|
-
|
325
|
+
# Net::HTTP is weird in that it treats nils like empty strings.
|
326
|
+
[nil, ''].should include(@request.body)
|
327
|
+
[nil, 0].should include(@request.content_length)
|
326
328
|
end
|
327
329
|
end
|
328
330
|
|
data/tasks/gem.rake
CHANGED
@@ -30,7 +30,7 @@ namespace :gem do
|
|
30
30
|
s.add_development_dependency("diff-lcs", "~> 1.1.2")
|
31
31
|
|
32
32
|
s.add_development_dependency("typhoeus", "~> 0.1.31")
|
33
|
-
s.add_development_dependency("rack", "~> 1.2.
|
33
|
+
s.add_development_dependency("rack", "~> 1.2.0")
|
34
34
|
|
35
35
|
s.require_path = "lib"
|
36
36
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpadapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bob Aman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-04 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -122,12 +122,12 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
hash:
|
125
|
+
hash: 31
|
126
126
|
segments:
|
127
127
|
- 1
|
128
128
|
- 2
|
129
|
-
-
|
130
|
-
version: 1.2.
|
129
|
+
- 0
|
130
|
+
version: 1.2.0
|
131
131
|
type: :development
|
132
132
|
version_requirements: *id007
|
133
133
|
description: |
|
@@ -141,6 +141,7 @@ extensions: []
|
|
141
141
|
extra_rdoc_files:
|
142
142
|
- README
|
143
143
|
files:
|
144
|
+
- lib/httpadapter/adapters/mock.rb
|
144
145
|
- lib/httpadapter/adapters/net_http.rb
|
145
146
|
- lib/httpadapter/adapters/rack.rb
|
146
147
|
- lib/httpadapter/adapters/typhoeus.rb
|