# coding: utf-8 # just to render sha1 different from cocaine.context import Dispatch, Log from cocaine.http import http from cocaine.timers import timer from cocaine.fs import fs from hashlib import sha512 log = Log() dispatch = Dispatch() @http def hash_headers(request, response): def process(): result = "<html><head>Hash</head>%s</html>\r\n" % sha512(str(request.headers)).hexdigest() response.writeHead(200, {"Content-Type": "text/plain"}) response.write(result) response.close() request.on("request", process) def reverse_echo(request, response): def process(chunk):
# coding: utf-8 from cocaine.context import Log, Dispatch from cocaine.http import http from hashlib import sha512 log = Log() dispatch = Dispatch() @http def hash_headers(request, response): def process(): result = "<html><head>Hash</head>%s</html>\r\n" % sha512(str(request.headers)).hexdigest() response.writeHead(200, { 'Content-Type': 'text/plain' }) response.write(result) response.close() request.on("request", process) dispatch.on("hash", hash_headers)
# coding: utf-8 from cocaine.context import Dispatch, Log import datetime log = Log() dispatch = Dispatch() def time_echo(request, response): def process(chunk): response.write(chunk + " " + str(datetime.datetime.now())) request.on("chunk", process) dispatch.on("echo", time_echo)
# coding: utf-8 from cocaine.context import Log, Dispatch from cocaine.http import http from hashlib import sha512 log = Log() dispatch = Dispatch() @http def hash_headers(request, response): def process(): result = "<html><head>Hash</head>%s</html>\r\n" % sha512( str(request.headers)).hexdigest() response.writeHead(200, {'Content-Type': 'text/plain'}) response.write(result) response.close() request.on("request", process) dispatch.on("hash", hash_headers)