class GV::Valley::FileServer::Api
Public Instance Methods
on_body(env, data)
click to toggle source
# File lib/gv/valley/file_server.rb, line 42 def on_body(env, data) (env['async-body'] ||= '') << data end
on_headers(env, headers)
click to toggle source
# File lib/gv/valley/file_server.rb, line 38 def on_headers(env, headers) env['async-headers'] = headers end
response(env)
click to toggle source
# 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' headers = {'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 headers.merge!( 'X-Stream' => 'Goliath') chunked_streaming_response(200, headers) 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