import urllib
from twisted.internet import protocol, reactor
from twisted.protocols import basic
class ReflectProtocol(basic.LineReceiver):
	def lineReceived(self, line):
		print ">>>", line, "<<<"
		if line.startswith("GET / "):
			self.transport.write('HTTP/1.1 200\r\nContent-Type: text/html\r\n\r\n')
			self.transport.write(open('headers.html').read())
			self.transport.loseConnection()
		elif line.startswith("GET /"):
			name = urllib.unquote(line[5:-9])
			self.transport.write(name)
			self.transport.loseConnection()
class ReflectFactory(protocol.ServerFactory):
	protocol = ReflectProtocol
reactor.listenTCP(1079, ReflectFactory())
reactor.run()
