Created
March 23, 2009 23:16
-
-
Save rsms/83844 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
#!/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