# File lib/mongrel/handlers.rb, line 193
    def send_file(req_path, request, response, header_only=false)

      stat = File.stat(req_path)

      # Set the last modified times as well and etag for all files
      mtime = stat.mtime
      # Calculated the same as apache, not sure how well the works on win32
      etag = Const::ETAG_FORMAT % [mtime.to_i, stat.size, stat.ino]

      modified_since = request.params[Const::HTTP_IF_MODIFIED_SINCE]
      none_match = request.params[Const::HTTP_IF_NONE_MATCH]

      # test to see if this is a conditional request, and test if
      # the response would be identical to the last response
      same_response = case
                      when modified_since && !last_response_time = Time.httpdate(modified_since) rescue nil then false
                      when modified_since && last_response_time > Time.now                                  then false
                      when modified_since && mtime > last_response_time                                     then false
                      when none_match     && none_match == '*'                                              then false
                      when none_match     && !none_match.strip.split(/\s*,\s*/).include?(etag)              then false
                      else modified_since || none_match  # validation successful if we get this far and at least one of the header exists
                      end

      header = response.header
      header[Const::ETAG] = etag

      if same_response
        response.start(304) {}
      else
        
        # First we setup the headers and status then we do a very fast send on the socket directly
        
        # Support custom responses except 404, which is the default. A little awkward. 
        response.status = 200 if response.status == 404        
        header[Const::LAST_MODIFIED] = mtime.httpdate

        # Set the mime type from our map based on the ending
        dot_at = req_path.rindex('.')
        if dot_at
          header[Const::CONTENT_TYPE] = MIME_TYPES[req_path[dot_at .. -1]] || @default_content_type
        else
          header[Const::CONTENT_TYPE] = @default_content_type
        end

        # send a status with out content length
        response.send_status(stat.size)
        response.send_header

        if not header_only
          response.send_file(req_path, stat.size < Const::CHUNK_SIZE * 2)
        end
      end
    end