diff --git a/examples/random_thrash.rb b/examples/random_thrash.rb new file mode 100644 index 00000000..fe9311ca --- /dev/null +++ b/examples/random_thrash.rb @@ -0,0 +1,19 @@ +require 'socket' +devrand = open("/dev/random","r") + +loop do + s = TCPSocket.new(ARGV[0],ARGV[1]) + s.write("GET / HTTP/1.1\r\n") + total = 0 + begin + loop do + r = devrand.read(10) + n = s.write(r) + total += n + end + rescue Object + STDERR.puts "#$!: #{total}" + end + s.close + sleep 1 +end diff --git a/ext/http11/http11.c b/ext/http11/http11.c index d89f0d42..55ecc0fd 100644 --- a/ext/http11/http11.c +++ b/ext/http11/http11.c @@ -124,10 +124,20 @@ void header_done(void *data, const char *at, size_t length) VALUE temp = Qnil; VALUE host = Qnil; VALUE port = Qnil; + VALUE ctype = Qnil; + VALUE clen = Qnil; char *colon = NULL; - rb_hash_aset(req, global_content_length, rb_hash_aref(req, global_http_content_length)); - rb_hash_aset(req, global_content_type, rb_hash_aref(req, global_http_content_type)); + clen = rb_hash_aref(req, global_http_content_length); + if(clen != Qnil) { + rb_hash_aset(req, global_content_length, clen); + } + + ctype = rb_hash_aref(req, global_http_content_type); + if(ctype != Qnil) { + rb_hash_aset(req, global_content_type, Qnil); + } + rb_hash_aset(req, global_gateway_interface, global_gateway_interface_value); if((temp = rb_hash_aref(req, global_http_host)) != Qnil) { // ruby better close strings off with a '\0' dammit diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb index b3081946..6bc2a704 100644 --- a/lib/mongrel/handlers.rb +++ b/lib/mongrel/handlers.rb @@ -169,7 +169,7 @@ module Mongrel ext = req[dot_at .. -1] if MIME_TYPES[ext] stat = File.stat(req) - response.header[Const::CONTENT_TYPE] = MIME_TYPES[ext] + response.header[Const::CONTENT_TYPE] = MIME_TYPES[ext] || "text" # TODO: Confirm this works for rfc 1123 response.header[Const::LAST_MODIFIED] = HttpServer.httpdate(stat.mtime) # TODO that this is a valid way to calculate an etag @@ -187,7 +187,7 @@ module Mongrel else File.open(req, "rb") { |f| response.socket.write(f.read) } end - rescue EOFError,Errno::ECONNRESET,Errno::EPIPE + rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL # ignore these since it means the client closed off early end else diff --git a/lib/mongrel/rails.rb b/lib/mongrel/rails.rb index 66db6914..611fcd08 100644 --- a/lib/mongrel/rails.rb +++ b/lib/mongrel/rails.rb @@ -132,7 +132,8 @@ module Mongrel $orig_dollar_quote = $".clone ENV['RAILS_ENV'] = ops[:environment] - require "#{ops[:cwd]}/config/environment" + env_location = "#{ops[:cwd]}/config/environment" + require env_location require 'dispatcher' require 'mongrel/rails'