I am trying to run a python CGI server. The cgi-bin folder in server has the test.cgi file. I am sending a curl request to this server and am expecting the request header to be printed in the CGI. I saw several stackoverflow pages suggesting using os.environ variables to get the header information. However, I don't get the request headers from environ values.
I am running a python CGI server using the following code:
from http.server import HTTPServer, CGIHTTPRequestHandler
server = HTTPServer
handler = CGIHTTPRequestHandler
server_address("", 8080)
handler.cgi_directories = ["/cgi-bin"]
httpd = server(server_address, handler)
httpd.serve_forever
I have a test.cgi script in cgi-bin folder. The test.cgi has the following code
import os
import cgi
print "content type: text/html"
for headername, headervalue in os.environ.iteritems():
print "<p> {0} = {1} </p>".format(headername,headervalue) <--- This prints Content-length header but not someheader
sample curl request curl -i -X GET "http:127.0.0.1/cgi-bin/test.cgi" -H "someheader : value"