Skip to content

Instantly share code, notes, and snippets.

@shyal

shyal/talk_gists.py

Created Feb 15, 2017
Embed
What would you like to do?
from tornado import gen, web, ioloop, httpclient
import json
class MainHandler(web.RequestHandler):
@gen.coroutine
def get(self):
http_client = httpclient.AsyncHTTPClient()
time, ip, headers = yield [http_client.fetch("http://time.ioloop.io?format=json"),
http_client.fetch("http://ip.ioloop.io?format=json"),
http_client.fetch("http://headers.ioloop.io?format=json")]
self.write({
"time": json.loads(time.body),
"ip": json.loads(ip.body),
"headers": json.loads(headers.body)
})
from hoverpy import HoverPy
from hoverpy import ext
from tornado.options import define, options, parse_command_line
define("virtualise", default=False, help="Proxy through our Service Virtualisation Server")
define("capture", default=False, help="Capture the requests if True, else simulate them. Requires the virtualise flag.")
def run_server():
app = web.Application([("/", MainHandler)])
app.listen(8080)
ioloop.IOLoop.current().start()
parse_command_line()
if options.virtualise:
ext.tor.configure()
with HoverPy(capture=options.capture):
print("starting virtual tornado server, capture: " + str(options.capture))
run_server()
else:
print("starting regular tornado server")
run_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.