#! /usr/bin/env python # -*- encoding: utf-8 -*- """ This application defines an http server that reads http posts and prints them in the commandline. Is a debugging purpose application. """ __author__ = "Leonardo M. Rocha" __copyright__ = "Copyright (C) 2012, Leonardo M. Rocha, INRIA" __revision__ = "1" __version__ = "1" import sys,os import BaseHTTPServer class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(self): print "Is calling the GET message" self.log_message("Command: %s Path: %s Headers: %r:" %(self.command, self.path, self.headers.items() ) ) if self.headers.has_key('content-length'): length = int(self.headers['content-length']) print self.rfile.read(length) def do_POST(self): print "is calling the POST method" self.log_message("Command: %s Path: %s Headers: %r:" %(self.command, self.path, self.headers.items() ) ) if self.headers.has_key('content-length'): length = int(self.headers['content-length']) print "Content: " print self.rfile.read(length) print "END content" def respond(self): print "responding message" body = "XML received OK" self.send_response(200) #say everything is OK to the client ;) self.send_header("Content-type", "text/plain") self.send_header("Content-length",str(len(body)) ) self.end_headers() self.wfile.write(body) def main(handler_class=HttpHandler, server_address = ('',8989), ): server = BaseHTTPServer.HTTPServer(server_address, handler_class) #server.handle_request() server.serve_forever() if __name__ == '__main__': sys.exit(main())