igrigorik-em-http-request 0.1.6 → 0.1.7

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.
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'em-http-request'
3
- s.version = '0.1.6'
3
+ s.version = '0.1.7'
4
4
  s.date = '2009-03-20'
5
5
  s.summary = 'EventMachine based HTTP Request interface'
6
6
  s.description = s.summary
@@ -171,6 +171,9 @@ module EventMachine
171
171
 
172
172
  # start HTTP request once we establish connection to host
173
173
  def connection_completed
174
+ ssl = @options[:tls] || @options[:ssl] || {}
175
+ start_tls(ssl) if @uri.scheme == "https" or @uri.port == 443
176
+
174
177
  send_request_header
175
178
  send_request_body
176
179
  end
@@ -191,10 +194,18 @@ module EventMachine
191
194
  unbind
192
195
  end
193
196
 
197
+ def normalize_body
198
+ if @options[:body].is_a? Hash
199
+ @options[:body].to_params
200
+ else
201
+ @options[:body]
202
+ end
203
+ end
204
+
194
205
  def send_request_header
195
206
  query = @options[:query]
196
207
  head = @options[:head] ? munge_header_keys(@options[:head]) : {}
197
- body = @options[:body]
208
+ body = normalize_body
198
209
 
199
210
  # Set the Host header if it hasn't been specified already
200
211
  head['host'] ||= encode_host
@@ -220,11 +231,7 @@ module EventMachine
220
231
 
221
232
  def send_request_body
222
233
  return unless @options[:body]
223
- if @options[:body].is_a? Hash
224
- body = @options[:body].to_params
225
- else
226
- body = @options[:body]
227
- end
234
+ body = normalize_body
228
235
  send_data body
229
236
  end
230
237
 
data/test/stallion.rb CHANGED
@@ -80,6 +80,9 @@ Stallion.saddle :spec do |stable|
80
80
  elsif stable.request.path_info == '/echo_query'
81
81
  stable.response.write stable.request.query_string
82
82
 
83
+ elsif stable.request.path_info == '/echo_content_length'
84
+ stable.response.write stable.request.content_length
85
+
83
86
  elsif stable.request.post?
84
87
  stable.response.write stable.request.body.read
85
88
 
data/test/test_request.rb CHANGED
@@ -145,6 +145,20 @@ describe EventMachine::HttpRequest do
145
145
  }
146
146
  }
147
147
  end
148
+
149
+ it "should perform successfull POST with Ruby Hash/Array as params and with the correct content length" do
150
+ EventMachine.run {
151
+ http = EventMachine::HttpRequest.new('http://127.0.0.1:8080/echo_content_length').post :body => {"key1" => "data1"}
152
+
153
+ http.errback { failed }
154
+ http.callback {
155
+ http.response_header.status.should == 200
156
+
157
+ http.response.to_i.should == 10
158
+ EventMachine.stop
159
+ }
160
+ }
161
+ end
148
162
 
149
163
  it "should perform successfull GET with custom header" do
150
164
  EventMachine.run {
@@ -277,4 +291,16 @@ describe EventMachine::HttpRequest do
277
291
  }
278
292
  end
279
293
 
294
+ it "should initiate SSL/TLS on HTTPS connections" do
295
+ EventMachine.run {
296
+ http = EventMachine::HttpRequest.new('https://mail.google.com:443/mail/').get
297
+
298
+ http.errback { failed }
299
+ http.callback {
300
+ http.response_header.status.should == 302
301
+ EventMachine.stop
302
+ }
303
+ }
304
+ end
305
+
280
306
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: igrigorik-em-http-request
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Grigorik