#!/usr/bin/env python """ HTTP HEAD Script Abstract: Sends HTTP HEAD requests to arbitrary Web pages License: GPL 2; share and enjoy! Author: Sean B. Palmer, inamidst.com Date: 2004-06 --- HTTP HEAD Webservice

HTTP HEAD Service

URI

View the Python source code. Nearby services: the W3C's HTTP HEAD service.

Sean B. Palmer
""" import cgitb; cgitb.enable() import sys, os, cgi, urllib method = os.environ.get('REQUEST_METHOD') form = cgi.FieldStorage() form.__call__ = lambda s: form[s].value def serve(status, body, mime=None): mime = mime or 'text/html' sys.stdout.write("Status: %s\r\n" % status) sys.stdout.write("Content-Type: %s; charset=utf-8\r\n\r\n" % mime) sys.stdout.write(body) sys.exit() def homepage(): i = __doc__.find('---') serve(200, __doc__[i+3:]) def head(uri): try: u = urllib.urlopen(uri) except Exception, e: serve(500, "

Error: %s.

" % cgi.escape(str(e))) info = u.info() u.close() serve(200, str(info), "text/plain") def main(): if form.has_key('uri'): head(form('uri')) elif method == 'GET': homepage() else: serve(501, "

Only GET is supported.

\n") if __name__=="__main__": main()