66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/vendor/rack-1.5.2/lib/rack/file.rb', line 66
def serving(env)
last_modified = F.mtime(@path).httpdate
return [304, {}, []] if env['HTTP_IF_MODIFIED_SINCE'] == last_modified
= { "Last-Modified" => last_modified }
mime = Mime.mime_type(F.extname(@path), @default_mime)
["Content-Type"] = mime if mime
.each { |field, content| [field] = content } if
response = [ 200, , env["REQUEST_METHOD"] == "HEAD" ? [] : self ]
size = F.size?(@path) || Utils.bytesize(F.read(@path))
ranges = Rack::Utils.byte_ranges(env, size)
if ranges.nil? || ranges.length > 1
response[0] = 200
@range = 0..size-1
elsif ranges.empty?
response = fail(416, "Byte range unsatisfiable")
response[1]["Content-Range"] = "bytes */#{size}"
return response
else
@range = ranges[0]
response[0] = 206
response[1]["Content-Range"] = "bytes #{@range.begin}-#{@range.end}/#{size}"
size = @range.end - @range.begin + 1
end
response[1]["Content-Length"] = size.to_s
response
end
|