Skip to content

Instantly share code, notes, and snippets.

@bigcurl
Created May 14, 2011 15:25
Show Gist options
  • Save bigcurl/972318 to your computer and use it in GitHub Desktop.
Save bigcurl/972318 to your computer and use it in GitHub Desktop.
A simple goliath API that is supposed to take the hash of an uploaded stream.
#!/usr/bin/env ruby
# encoding: utf-8
require 'goliath'
require 'digest/sha1'
class ShaStream < Goliath::API
# use Goliath::Rack::Params
def on_headers(env, headers)
env['async-digest'] = Digest::SHA1.new # SHA1 or MD5
end
def on_body(env, data)
env['async-digest'] << data
end
def response(env)
[200, {}, ["sha1: #{env['async-digest'].hexdigest}\n"]]
end
end
# run with ruby sha_stream.rb -sv -p 9000
# call with curl -F "file=@goliath/github.rb" "localhost:9000/stream"
# expected behavior: sha1 should always be the same
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment