46
47
48
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
|
# File 'lib/gv/valley/file_server.rb', line 46
def response(env)
path = "#{ENV['GV_HOME']}/#{env['REQUEST_PATH']}"
case env['REQUEST_METHOD']
when 'GET'
= {'X-filename' => path}
raise Goliath::Validation::NotFoundError unless File.file?(path)
operation = proc do
FileSystem.new(path).get { |chunk| env.chunked_stream_send(chunk) }
end
callback = proc do |result|
env.chunked_stream_close
end
EM.defer operation, callback
.merge!( 'X-Stream' => 'Goliath')
chunked_streaming_response(200, )
when 'PUT'
File.delete(path) rescue nil
result = File.open(path, File::RDWR|File::CREAT){ |f| f.puts env['async-body'] }
[ 200, {}, {body: "OK"} ]
when 'DELETE'
result = File.delete(path)
[ 200, {}, {body: result } ]
end
end
|