/
app.rb
52 lines (45 loc) · 1 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
require 'digest/md5'
# before do
# headers 'Cache-Control' => 'max-age=10'
# end
get '/' do
@posts = Post.order('created_at DESC').first(3)
@songs = Rdio.top_charts('bacon')
# 1
erb :index
# 2
# html = erb :index
# digest = Digest::MD5.hexdigest(html)
#
# if request.env['HTTP_IF_NONE_MATCH'] == digest
# # Return 304 Not Modified with empty body
# 304
# else
# # Send response with ETag header
# headers 'ETag' => digest
# html
# end
# 3
# html = erb :index
# etag Digest::MD5.hexdigest(html)
# html
end
get '/posts/:id' do
@post = Post.find(params[:id])
# 1
erb :show
# 2
# ims = request.env['HTTP_IF_MODIFIED_SINCE']
# ims = Time.httpdate(ims) if ims
#
# if ims && ims >= @post.updated_at
# # Return 304 Not Modified with empty body
# 304
# else
# # Render view and send response with Last-Modified header
# headers 'Last-Modified' => @post.updated_at.httpdate
# erb :show
# end
# 3
# last_modified @post.updated_at
end