def publish_file(req_path, local_path, request, response)
case (request.method)
when 'GET', 'HEAD'
File.open(local_path) { |file|
stat = file.stat
if (request.has_header? 'If-Modified-Since') then
publish_if_modified_since(stat, request, response) and return
elsif (request.has_header? 'If-Unmodified-Since') then
publish_if_unmodified_since(stat, request, response) and return
elsif (request.has_header? 'If-Range') then
if (request.has_header? 'Range') then
publish_if_range(file, stat, req_path, request, response) and return
end
end
if (request.has_header? 'Range') then
if (! (request.has_header? 'If-Range')) then
publish_range(file, stat, req_path, request, response) and return
end
end
response.status = 200
response.set_header('Content-Type', @type_resolver.content_type(req_path))
response.set_header('Content-Length', stat.size.to_s)
response.set_header('Last-Modified', stat.mtime.httpdate)
response.start_body
if (request.method != 'HEAD') then
while (data = file.read(@chunk_size))
response.write(data)
end
end
}
else
http_error = HTTPError.new(405)
http_error.set_header('Allow', 'GET, HEAD')
raise http_error
end
nil
end