49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/fakes3/server.rb', line 49
def do_GET(request, response)
s_req = normalize_request(request)
case s_req.type
when 'LIST_BUCKETS'
response.status = 200
response['Content-Type'] = 'application/xml'
buckets = @store.buckets
response.body = XmlAdapter.buckets(buckets)
when 'LS_BUCKET'
bucket_obj = @store.get_bucket(s_req.bucket)
if bucket_obj
response.status = 200
response['Content-Type'] = "application/xml"
query = {
:marker => s_req.query["marker"] ? s_req.query["marker"].to_s : nil,
:prefix => s_req.query["prefix"] ? s_req.query["prefix"].to_s : nil,
:max_keys => s_req.query["max_keys"] ? s_req.query["max_keys"].to_s : nil,
:delimiter => s_req.query["delimiter"] ? s_req.query["delimiter"].to_s : nil
}
bq = bucket_obj.query_for_range(query)
response.body = XmlAdapter.bucket_query(bq)
else
response.status = 404
response.body = XmlAdapter.error_no_such_bucket(s_req.bucket)
response['Content-Type'] = "application/xml"
end
when 'GET_ACL'
response.status = 200
response.body = XmlAdapter.acl()
response['Content-Type'] = 'application/xml'
when 'GET'
real_obj = @store.get_object(s_req.bucket,s_req.object,request)
if !real_obj
response.status = 404
response.body = ""
return
end
response.status = 200
response['Content-Type'] = real_obj.content_type
stat = File::Stat.new(real_obj.io.path)
response['Last-Modified'] = stat.mtime.iso8601()
response.['ETag'] = "\"#{real_obj.md5}\""
response['Accept-Ranges'] = "bytes"
response['Last-Ranges'] = "bytes"
content_length = stat.size
if range = request.["range"].first
response.status = 206
if range =~ /bytes=(\d*)-(\d*)/
start = $1.to_i
finish = $2.to_i
finish_str = ""
if finish == 0
finish = content_length - 1
finish_str = "#{finish}"
else
finish_str = finish.to_s
end
bytes_to_read = finish - start + 1
response['Content-Range'] = "bytes #{start}-#{finish_str}/#{content_length}"
real_obj.io.pos = start
response.body = real_obj.io.read(bytes_to_read)
return
end
end
response['Content-Length'] = File::Stat.new(real_obj.io.path).size
response['Last-Modified'] = real_obj.modified_date
if s_req.http_verb == 'HEAD'
response.body = ""
else
response.body = real_obj.io
end
end
end
|