Created
February 15, 2017 14:24
-
-
Save shyal/a52714555a29e8998daec83a1305a914 to your computer and use it in GitHub Desktop.
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
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