diff options
Diffstat (limited to 'lib/yahns/http_response.rb')
-rw-r--r-- | lib/yahns/http_response.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index d957df6..88ff9f9 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -9,7 +9,7 @@ require_relative 'wbuf_str' # You use it by simply doing: # # status, headers, body = rack_app.call(env) -# http_response_write(status, headers, body) +# http_response_write(status, headers, body, env['REQUEST_METHOD']=='HEAD') # # Most header correctness (including Content-Length and Content-Type) # is the job of Rack, with the exception of the "Date" header. @@ -118,13 +118,9 @@ module Yahns::HttpResponse # :nodoc: end end - def have_more?(value) - value.to_i > 0 && @hs.env['REQUEST_METHOD'] != 'HEAD'.freeze - end - # writes the rack_response to socket as an HTTP response # returns :wait_readable, :wait_writable, :forget, or nil - def http_response_write(status, headers, body) + def http_response_write(status, headers, body, hdr_only) offset = 0 count = hijack = nil k = self.class @@ -133,6 +129,7 @@ module Yahns::HttpResponse # :nodoc: if @hs.headers? code = status.to_i + hdr_only ||= Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(code) msg = Rack::Utils::HTTP_STATUS_CODES[code] buf = "#{response_start}#{msg ? %Q(#{code} #{msg}) : status}\r\n" \ "Date: #{httpdate}\r\n".dup @@ -150,7 +147,7 @@ module Yahns::HttpResponse # :nodoc: # allow Rack apps to tell us they want to drop the client alive = false if value =~ /\bclose\b/i when %r{\AContent-Length\z}i - flags |= MSG_MORE if have_more?(value) + flags |= MSG_MORE if value.to_i > 0 && !hdr_only kv_str(buf, key, value) when "rack.hijack" hijack = value @@ -181,6 +178,7 @@ module Yahns::HttpResponse # :nodoc: end return response_hijacked(hijack) if hijack + return http_response_done(alive) if hdr_only if body.respond_to?(:to_path) @state = body = Yahns::StreamFile.new(body, alive, offset, count) |