fredo 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.10
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fredo}
8
- s.version = "0.1.9"
8
+ s.version = "0.1.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ilpoldo"]
12
- s.date = %q{2010-05-04}
12
+ s.date = %q{2010-05-06}
13
13
  s.description = %q{Mocks web services by plugging Net::Http straight into Rack}
14
14
  s.email = %q{ilpoldo@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -50,27 +50,31 @@ module Net #:nodoc: all
50
50
  protocol = use_ssl? ? "https" : "http"
51
51
  full_path = "#{protocol}://#{self.address}:#{self.port}#{request.path}"
52
52
 
53
- rack_env ={'REQUEST_METHOD' => request.method,
54
- 'SCRIPT_NAME' => '',
55
- 'PATH_INFO' => uri.path,
56
- 'QUERY_STRING' => (uri.query || ''),
57
- 'SERVER_NAME' => self.address,
58
- 'SERVER_PORT' => self.port,
59
- 'rack.version' => [1,1],
60
- 'rack.url_scheme' => protocol,
61
- 'rack.input' => body,
62
- 'rack.errors' => $stderr,
63
- 'rack.multithread' => true,
64
- 'rack.multiprocess' => true,
65
- 'rack.run_once' => false}
53
+ # It's for testing, we care about all the headers
54
+ request_headers = request.instance_variable_get :@header
55
+ request_headers = Hash[*request_headers.map {|k,v| [String(k).upcase.gsub(%r{[^_0-9A-Z]},"_"),v]}.flatten]
56
+
57
+ rack_env =request_headers.merge({'REQUEST_METHOD' => request.method,
58
+ 'SCRIPT_NAME' => '',
59
+ 'PATH_INFO' => uri.path,
60
+ 'QUERY_STRING' => (uri.query || ''),
61
+ 'SERVER_NAME' => self.address,
62
+ 'SERVER_PORT' => self.port,
63
+ 'rack.version' => [1,1],
64
+ 'rack.url_scheme' => protocol,
65
+ 'rack.input' => body,
66
+ 'rack.errors' => $stderr,
67
+ 'rack.multithread' => true,
68
+ 'rack.multiprocess' => true,
69
+ 'rack.run_once' => false})
66
70
 
67
71
  # @socket = Net::HTTP.socket_type.new
68
72
  # Perform the request
69
- status, header, body = Fredo.call(rack_env)
73
+ status, headers, body = Fredo.call(rack_env)
70
74
 
71
75
  response = Net::HTTPResponse.send(:response_class, "#{status}").new("1.0", "#{status}", body)
72
76
  response.instance_variable_set(:@body, body)
73
- header.each { |name, value| response[name] = value }
77
+ headers.each { |name, value| response[name] = value }
74
78
  response.instance_variable_set(:@read, true)
75
79
 
76
80
  def response.read_body(*args, &block)
@@ -126,8 +126,19 @@ describe Fredo do
126
126
  end
127
127
 
128
128
  http = Net::HTTP.new('www.gossip.com')
129
- http.post('/', body, 'content-type' => 'text/plain').body.should eql(body)
129
+ http.post('/', body, 'Content-Type' => 'text/plain').body.should eql(body)
130
130
  end
131
131
 
132
132
  end
133
+
134
+ context "headers" do
135
+ it "keeps request headers" do
136
+ Fredo.post 'http://www.headheavy.com' do
137
+ "I got #{request.env['CONTENT_TYPE']}"
138
+ end
139
+
140
+ http = Net::HTTP.new('www.headheavy.com')
141
+ http.post('/', '<foo></foo>', 'content-type' => 'application/xml').body.should eql('I got application/xml')
142
+ end
143
+ end
133
144
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 9
9
- version: 0.1.9
8
+ - 10
9
+ version: 0.1.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - ilpoldo
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-04 00:00:00 +01:00
17
+ date: 2010-05-06 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency