From: Gabriel Genellina on
En Tue, 15 Jun 2010 00:41:08 -0300, shanti bhushan
<ershantibhushan(a)gmail.com> escribi�:

> Dear all,
> I have made local webserver up by the python script
>
> from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
>
> class MyHandler(BaseHTTPRequestHandler):
>
> def do_GET(self):
> try:
> if self.path.endswith(".html"):
> f = open(curdir + sep + self.path) #self.path has /
> [...]
>
> def main():
> try:
> server = HTTPServer(('', 80), MyHandler)
> print 'started httpserver...'
> server.serve_forever()
> [...]
>
>
> I have designed one html page also.
> when i access the HTML page ,i want to capture following things
> user_agents client-request ,server-response with the help of python
> script.
> please guide me to write such python script with which i can log all
> server /client request and response.

HTTPServer already logs the request - using sys.stderr, but you may
override log_message() if you want:
http://docs.python.org/library/basehttpserver.html#BaseHTTPServer.BaseHTTPRequestHandler.log_message

If you want to log the response, do that in the request handler, a good
place would be at the end of your do_GET() method above.

--
Gabriel Genellina