Created
October 6, 2011 17:54
-
-
Save jayd3e/1268108 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 httpserver, ioloop | |
from tornado.httpclient import AsyncHTTPClient, HTTPClient | |
class httpProxy(): | |
def __init__(self, iolp): | |
port = 5009 | |
self.myserv = httpserver.HTTPServer(self.handle_request) | |
self.myserv.listen(port) | |
print("Serving on " + str(port)) | |
#self.httpclient = HTTPClient() | |
#self.userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30" | |
self.ioloop = iolp.start() | |
def handle_request(self, req): | |
#body = self.httpclient.fetch(req.uri) | |
body = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link id="www-core-css" rel="stylesheet" href="http://s.ytimg.com/yt/cssbin/www-core-vflzqh5T9.css"> | |
</head> | |
<body> | |
HELLO | |
</body> | |
""" | |
resp = "HTTP/1.1 200 OK\r\nContent-Length: %d\r\n\r\n%s" % (len(body), body) | |
req.write(resp) | |
req.finish() | |
iolp = ioloop.IOLoop.instance() | |
server = httpProxy(iolp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment