Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (22 sloc) 0.697 kb
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
#!/usr/bin/env ruby
$:<< '../lib' << 'lib'

require 'goliath'
require 'yajl' if RUBY_PLATFORM != 'java'

class AsyncUpload < Goliath::API
  use Goliath::Rack::DefaultMimeType # cleanup accepted media types
  use Goliath::Rack::Render, 'json' # auto-negotiate response format

  def on_headers(env, headers)
    env.logger.info 'received headers: ' + headers.inspect
    env['async-headers'] = headers
  end

  def on_body(env, data)
    env.logger.info 'received data: ' + data
    (env['async-body'] ||= '') << data
  end

  def on_close(env)
    env.logger.info 'closing connection'
  end

  def response(env)
    [200, {}, {body: env['async-body'], head: env['async-headers']}]
  end
end
Something went wrong with that request. Please try again.