Skip to content

Instantly share code, notes, and snippets.

@akzhan
Last active May 24, 2017 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akzhan/9980efe4034fb2e6d029293895423843 to your computer and use it in GitHub Desktop.
Save akzhan/9980efe4034fb2e6d029293895423843 to your computer and use it in GitHub Desktop.
require "http/server"
require "openssl/digest"
server = HTTP::Server.new("127.0.0.1", 4000) do |context|
context.response.content_type = "text/plain"
if context.request.path != "/test"
context.response.print "Nok"
next
end
io = IO::Memory.new
File.open("/tmp/data") do |f|
b = Bytes.new(f.size)
f.read(b)
io = IO::Memory.new(b, false)
end
n = context.request.query_params["n"].to_i
s = ""
n.times do |i|
signer = OpenSSL::Digest.new("sha256")
io.rewind
signer << io
s = signer.hexdigest
end
context.response.print s
end
server.listen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment