harsh manvar

harsh manvar

1 Articles Published

Articles by harsh manvar

1 articles

How to read all HTTP headers in Python CGI script?

harsh manvar
harsh manvar
Updated on 27-Feb-2020 2K+ Views

It is possible to get a custom request header's value in an apache CGI script with python. The solution is similar to this.Apache's mod_cgi will set environment variables for each HTTP request header received, the variables set in this manner will all have an HTTP_ prefix, so for example x-client-version: 1.2.3 will be available as variable HTTP_X_CLIENT_VERSION.So, to read the above custom header just call os.environ["HTTP_X_CLIENT_VERSION"].The below script will print all HTTP_* headers and values −#!/usr/bin/env python import os print "Content-Type: text/html" print "Cache-Control: no-cache" print print "" for headername, headervalue in os.environ.iteritems():     if headername.startswith("HTTP_"):         print "{0} = {1}".format(headername, headervalue)   ...

Read More
Showing 1–1 of 1 articles
« Prev 1 Next »
Advertisements