Skip to content

Instantly share code, notes, and snippets.

@malceore
Created May 7, 2018 22:56
Show Gist options
  • Select an option

  • Save malceore/27a4f592035643cdd448f1bfd7cd1551 to your computer and use it in GitHub Desktop.

Select an option

Save malceore/27a4f592035643cdd448f1bfd7cd1551 to your computer and use it in GitHub Desktop.
from twisted.web import server, resource
from twisted.internet import reactor, endpoints
class Counter(resource.Resource):
isLeaf = True
numberRequests = 0
def render_GET(self, request):
self.numberRequests += 1
request.setHeader(b"content-type", b"text/plain")
content = u"I am request #{}\n".format(self.numberRequests)
return content.encode("ascii")
endpoints.serverFromString(reactor, "tcp:8090").listen(server.Site(Counter()))
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment