16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/attacheable/photo_handler.rb', line 16
def process(request, response)
if File.exists?(Attacheable.root+"/public#{@prefix}/#{request.params["PATH_INFO"]}")
response.start(200) do |, out|
["Content-Type"] = "image/jpeg"
out.write(File.read(Attacheable.root+"/public#{@prefix}/#{request.params["PATH_INFO"]}"))
end
return
end
start_time = Time.now
photo, data = klass.data_by_path_info(request.params["PATH_INFO"].split("/"))
if photo
response.start(200) do |, out|
["Content-Type"] = photo.content_type
out.write(data)
end
else
response.start(404) do |, out|
["Content-Type"] = "text/plain"
out.write("No such image\n")
end
end
logger.info "Processed request in #{Time.now - start_time} seconds\n URI: #{request.params["REQUEST_URI"]}\n\n"
rescue Exception => e
logger.info "!! Internal server error\nURI: #{request.params["REQUEST_URI"]}\n#{e}\n#{e.backtrace.join("\n")}"
logger.flush
response.start(200) do |, out|
["Content-Type"] = "text/plain"
out.write("Some error on server\n")
end
end
|