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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.2.1
2
+
3
+ * added mock adapter for testing
4
+
1
5
  == 0.2.0
2
6
 
3
7
  * abstracted transmission of HTTP requests
@@ -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(
@@ -18,7 +18,7 @@ unless defined? HTTPAdapter::VERSION
18
18
  module VERSION #:nodoc:
19
19
  MAJOR = 0
20
20
  MINOR = 2
21
- TINY = 0
21
+ TINY = 1
22
22
 
23
23
  STRING = [MAJOR, MINOR, TINY].join('.')
24
24
  end
@@ -322,7 +322,9 @@ describe HTTPAdapter::NetHTTPRequestAdapter,
322
322
  end
323
323
 
324
324
  it 'should convert the body properly' do
325
- @request.body.should == ''
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
 
@@ -60,7 +60,7 @@ describe HTTPAdapter::NetHTTPRequestAdapter, 'transmitting a GET tuple' do
60
60
  before do
61
61
  @tuple = [
62
62
  'GET',
63
- 'https://www.google.com/',
63
+ 'https://encrypted.google.com/',
64
64
  [],
65
65
  []
66
66
  ]
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.1")
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
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: 2010-09-07 00:00:00 -07:00
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: 29
125
+ hash: 31
126
126
  segments:
127
127
  - 1
128
128
  - 2
129
- - 1
130
- version: 1.2.1
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