Skip to content

Instantly share code, notes, and snippets.

@rsms
Created March 23, 2009 23:16
Show Gist options
  • Save rsms/83844 to your computer and use it in GitHub Desktop.
Save rsms/83844 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
'''A very simple HTTP server using eventlet (which in turn is based on greenlet)
'''
from eventlet import api, httpd, util
util.wrap_socket_with_coroutine_socket()
class Handler(object):
def handle_request(self, req):
path = req.path_segments()
if len(path) > 0 and path[0] == "notexist":
req.response(404, body='not found')
return
req.write('hello world\n')
def adapt(self, obj, req):
'Convert obj to bytes'
req.write(str(obj))
def main():
httpd.server(api.tcp_listener(('0.0.0.0', 8080)), Handler(), max_size=5000)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment