0
@@ -9,6 +9,7 @@ rescue => details
0
STDERR.puts "Whoops, had an error with loading mongrel as a gem. Trying just 'require'. Mongrel is required for testing."
0
+Mongrel::HTTP_STATUS_CODES[220] = "Unspecified success"
0
def uconvert(one, two, three); FeedParser::uconvert(one, two, three); end
0
def _ebcdic_to_ascii(one); FeedParser::_ebcdic_to_ascii(one); end
0
@@ -194,6 +195,61 @@ class FeedParserTestRequestHandler < Mongrel::DirHandler
0
+ # Overriding the send_file in DirHandler for a goddamn one line bug fix.
0
+ # Holy shit does this suck. Changing `response.status = 200` to
0
+ # `response.status ||= 200`. Also, adding Mongrel:: in front of the Const
0
+ # because subclassing makes them break.
0
+ def send_file(req_path, request, response, header_only=false)
0
+ stat = File.stat(req_path)
0
+ # Set the last modified times as well and etag for all files
0
+ # Calculated the same as apache, not sure how well the works on win32
0
+ etag = Mongrel::Const::ETAG_FORMAT % [mtime.to_i, stat.size, stat.ino]
0
+ modified_since = request.params[Mongrel::Const::HTTP_IF_MODIFIED_SINCE]
0
+ none_match = request.params[Mongrel::Const::HTTP_IF_NONE_MATCH]
0
+ # test to see if this is a conditional request, and test if
0
+ # the response would be identical to the last response
0
+ when modified_since && !last_response_time = Time.httpdate(modified_since) rescue nil : false
0
+ when modified_since && last_response_time > Time.now : false
0
+ when modified_since && mtime > last_response_time : false
0
+ when none_match && none_match == '*' : false
0
+ when none_match && !none_match.strip.split(/\s*,\s*/).include?(etag) : false
0
+ else modified_since || none_match # validation successful if we get this far and at least one of the header exists
0
+ header = response.header
0
+ header[Mongrel::Const::ETAG] = etag
0
+ response.start(304) {}
0
+ # first we setup the headers and status then we do a very fast send on the socket directly
0
+ response.status ||= 200
0
+ header[Mongrel::Const::LAST_MODIFIED] = mtime.httpdate
0
+ # set the mime type from our map based on the ending
0
+ dot_at = req_path.rindex('.')
0
+ header[Mongrel::Const::CONTENT_TYPE] = MIME_TYPES[req_path[dot_at .. -1]] || @default_content_type
0
+ header[Mongrel::Const::CONTENT_TYPE] = @default_content_type
0
+ # send a status with out content length
0
+ response.send_status(stat.size)
0
+ response.send_file(req_path, stat.size < Mongrel::Const::CHUNK_SIZE * 2)
Comments
No one has commented yet.