Permalink
Browse files

more fixes for multipart bodies

  • Loading branch information...
1 parent 4914451 commit e85d77c77235fbc9efff5711a492873b1325ffe7 @hukl committed Aug 15, 2010
Showing with 23 additions and 9 deletions.
  1. +7 −8 lib/rig/http.rb
  2. +16 −1 test/test_http.rb
View
@@ -28,7 +28,7 @@ def initialize *options
def send
begin
tcp_socket = TCPSocket.new( @options[:host], @options[:port] )
- tcp_socket.write( @header.to_s)# + @body.to_s )
+ tcp_socket.write( @header.to_s + @body.to_s )
response = tcp_socket.read
rescue => exception
puts exception.message
@@ -69,13 +69,12 @@ def normalize_options options
}
uri_options.merge( options.last )
when :advanced
- {
- :http_method => options.first[:http_method] || "GET",
- :host => options.first[:host],
- :port => options.first[:port] || 80,
- :path => options.first[:path] || "/",
- :query => options.first[:query]
- }
+ options.first[:http_method] ||= "GET"
+ options.first[:host]
+ options.first[:port] ||= 80
+ options.first[:path] ||= "/"
+ options.first[:query]
+ options.first
else
raise ArgumentError
end
View
@@ -77,7 +77,6 @@ class TestHttp < Test::Unit::TestCase
:port=>80,
:path=>"/",
:http_method=>"GET",
- :query => nil,
:content_type=>"text/plain",
:content_length=>0
}
@@ -208,6 +207,22 @@ class TestHttp < Test::Unit::TestCase
assert_equal 200, response.status
end
+ test "more advanced post request" do
+ request = Rig::HTTP.new(
+ :host => "beta.hoccer.com",
+ :path => "/events",
+ :http_method => "POST",
+ :body => {
+ "event[type]" => "Drop",
+ "event[latitude]" => "latitude",
+ "event[longitude]" => "longitude",
+ "event[location_accuracy]" => 100,
+ "event[lifetime]" => 600
+ }
+ )
+ assert_equal false, request.body.multipart?
+ end
+
#test "multipart body gets properly created" do
# post = HTTP.new(
# :host => "localhost",

0 comments on commit e85d77c

Please sign in to comment.