diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-08-03 20:49:11 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-08-03 20:49:11 +0000 |
commit | f6b9b509b26f00ff12f59ef8d186e14e2947abd3 (patch) | |
tree | 2df631b0e50fb8cd90d5cd4fc3c4f16d3d5b7f5a /lib/mongrel.rb | |
parent | 975a7aae803f4abf6fc1819b734bd504ca885255 (diff) | |
download | unicorn-f6b9b509b26f00ff12f59ef8d186e14e2947abd3.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@299 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib/mongrel.rb')
-rw-r--r-- | lib/mongrel.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/mongrel.rb b/lib/mongrel.rb index 6919c1a..e8f65e7 100644 --- a/lib/mongrel.rb +++ b/lib/mongrel.rb @@ -145,7 +145,7 @@ module Mongrel MAX_BODY=MAX_HEADER # A frozen format for this is about 15% faster - STATUS_FORMAT = "HTTP/1.1 %d %s\r\nContent-Length: %d\r\nConnection: close\r\n".freeze + STATUS_FORMAT = "HTTP/1.1 %d %s\r\nConnection: close\r\n".freeze CONTENT_TYPE = "Content-Type".freeze LAST_MODIFIED = "Last-Modified".freeze ETAG = "ETag".freeze @@ -159,7 +159,7 @@ module Mongrel LINE_END="\r\n".freeze REMOTE_ADDR="REMOTE_ADDR".freeze HTTP_X_FORWARDED_FOR="HTTP_X_FORWARDED_FOR".freeze - HTTP_IF_UNMODIFIED_SINCE="HTTP_IF_UNMODIFIED_SINCE".freeze + HTTP_IF_MODIFIED_SINCE="HTTP_IF_MODIFIED_SINCE".freeze HTTP_IF_NONE_MATCH="HTTP_IF_NONE_MATCH".freeze REDIRECT = "HTTP/1.1 302 Found\r\nLocation: %s\r\nConnection: close\r\n\r\n".freeze end @@ -397,10 +397,10 @@ module Mongrel end end - def send_status(content_length=nil) + def send_status(content_length=@body.length) if not @status_sent - content_length ||= @body.length - write(Const::STATUS_FORMAT % [status, HTTP_STATUS_CODES[@status], content_length]) + @header['Content-Length'] = content_length unless @status == 304 + write(Const::STATUS_FORMAT % [@status, HTTP_STATUS_CODES[@status]]) @status_sent = true end end @@ -643,16 +643,29 @@ module Mongrel end end + def configure_socket_options + if /linux/ === RUBY_PLATFORM + # 9 is currently TCP_DEFER_ACCEPT + $tcp_defer_accept_opts = [9,1] + $tcp_cork_opts = [3,1] + end + end # Runs the thing. It returns the thread used so you can "join" it. You can also # access the HttpServer::acceptor attribute to get the thread later. def run BasicSocket.do_not_reverse_lookup=true + configure_socket_options + + @socket.setsockopt(Socket::SOL_TCP, $tcp_defer_accept_opts[0], $tcp_defer_accept_opts[1]) if $tcp_defer_accept_opts + @acceptor = Thread.new do while true begin client = @socket.accept + client.setsockopt(Socket::SOL_TCP, $tcp_cork_opts[0], $tcp_cork_opts[1]) if $tcp_cork_opts + worker_list = @workers.list if worker_list.length >= @num_processors |