-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
54 lines (40 loc) · 1.41 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
47
48
49
50
51
52
53
54
require 'digest/md5'
require 'digest/sha1'
require 'logger'
error do
e = @env['sinatra.error']
request.body.rewind if request.body.respond_to?('rewind')
text = []
text.push "Internal Server Error - #{e.class} #{e.message}"
Logger.err text[0], @env
e.backtrace.each { |line| Logger.err(line, @env); text.push line }
halt 500, { 'Content-Type' => 'text/plain' }, text.join("\n") + "\n"
end
configure do
disable :logging # Stop CommonLogger from logging to STDERR, please.
disable :dump_errors # Set to true in 'classic' style apps (of which this is one) regardless of :environment; it
# adds a backtrace to STDERR on all raised errors (even those we properly handle). Not so good.
set :environment, :production # Get some exceptional defaults.
set :raise_errors, false # Handle our own errors
Logger.setup('SimpleGet')
Logger.stderr
end
put '/:name' do |name|
start = Time.now
data = request.body
if not data.respond_to? "read"
halt 500, "data not readable"
end
md5 = Digest::MD5.new
sha1 = Digest::SHA1.new
size = 0
while buff = data.read(4 * 1024 * 1024)
size += buff.length
md5 << buff
sha1 << buff
end
status 200
headers 'Content-Type' => 'text/plain'
"Name: #{name}; MD5: #{md5.hexdigest}; SHA1: #{sha1.hexdigest}; size: #{size}\n" +
"Started: #{start}; finished: #{Time.now}\n"
end