Created
May 14, 2011 15:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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