Permalink
Browse files

eof on read should return '' instead of nil

closes #146
  • Loading branch information...
1 parent d98bc67 commit e3890682f2b95e4f35ac172c1276ee9adbc29048 @geemus geemus committed Oct 16, 2012
Showing with 30 additions and 1 deletion.
  1. +1 −1 lib/excon/socket.rb
  2. +12 −0 tests/bad_tests.rb
  3. +17 −0 tests/servers/eof.rb
View
@@ -78,7 +78,7 @@ def connect
def read(max_length=nil)
return nil if @eof
if @eof
- nil
+ ''
elsif @params[:nonblock]
begin
if max_length
View
@@ -32,4 +32,16 @@
end
+ with_server('eof') do
+
+ tests('eof server: causes EOFError') do
+
+ tests('request').raises(Excon::Errors::SocketError) do
+ Excon.get('http://127.0.0.1:9292/eof')
+ end
+
+ end
+
+ end
+
end
View
@@ -0,0 +1,17 @@
+#!/usr/bin/env ruby
+
+require "eventmachine"
+
+module EOFServer
+ def receive_data(data)
+ case data
+ when %r{^GET /eof\s}
+ close_connection(true)
+ end
+ end
+end
+
+EM.run do
+ EM.start_server("127.0.0.1", 9292, EOFServer)
+ $stderr.puts "ready"
+end

0 comments on commit e389068

Please sign in to comment.