Merged revisions 85202 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85202 | senthil.kumaran | 2010-10-03 23:25:45 +0530 (Sun, 03 Oct 2010) | 4 lines Fix Issue9272 - Change CGIHTTPServer to give the child program a copy of os.environ ........
This commit is contained in:
parent
ec2ee17cf8
commit
a9bd0cc67e
|
@ -29,6 +29,7 @@ import urllib
|
||||||
import BaseHTTPServer
|
import BaseHTTPServer
|
||||||
import SimpleHTTPServer
|
import SimpleHTTPServer
|
||||||
import select
|
import select
|
||||||
|
import copy
|
||||||
|
|
||||||
|
|
||||||
class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
|
@ -154,7 +155,7 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
|
|
||||||
# Reference: http://hoohoo.ncsa.uiuc.edu/cgi/env.html
|
# Reference: http://hoohoo.ncsa.uiuc.edu/cgi/env.html
|
||||||
# XXX Much of the following could be prepared ahead of time!
|
# XXX Much of the following could be prepared ahead of time!
|
||||||
env = {}
|
env = copy.deepcopy(os.environ)
|
||||||
env['SERVER_SOFTWARE'] = self.version_string()
|
env['SERVER_SOFTWARE'] = self.version_string()
|
||||||
env['SERVER_NAME'] = self.server.server_name
|
env['SERVER_NAME'] = self.server.server_name
|
||||||
env['GATEWAY_INTERFACE'] = 'CGI/1.1'
|
env['GATEWAY_INTERFACE'] = 'CGI/1.1'
|
||||||
|
@ -216,7 +217,6 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH',
|
for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH',
|
||||||
'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
|
'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'):
|
||||||
env.setdefault(k, "")
|
env.setdefault(k, "")
|
||||||
os.environ.update(env)
|
|
||||||
|
|
||||||
self.send_response(200, "Script output follows")
|
self.send_response(200, "Script output follows")
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
pass
|
pass
|
||||||
os.dup2(self.rfile.fileno(), 0)
|
os.dup2(self.rfile.fileno(), 0)
|
||||||
os.dup2(self.wfile.fileno(), 1)
|
os.dup2(self.wfile.fileno(), 1)
|
||||||
os.execve(scriptfile, args, os.environ)
|
os.execve(scriptfile, args, env)
|
||||||
except:
|
except:
|
||||||
self.server.handle_error(self.request, self.client_address)
|
self.server.handle_error(self.request, self.client_address)
|
||||||
os._exit(127)
|
os._exit(127)
|
||||||
|
@ -274,7 +274,8 @@ class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
p = subprocess.Popen(cmdline,
|
p = subprocess.Popen(cmdline,
|
||||||
stdin = subprocess.PIPE,
|
stdin = subprocess.PIPE,
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
stderr = subprocess.PIPE
|
stderr = subprocess.PIPE,
|
||||||
|
env = env
|
||||||
)
|
)
|
||||||
if self.command.lower() == "post" and nbytes > 0:
|
if self.command.lower() == "post" and nbytes > 0:
|
||||||
data = self.rfile.read(nbytes)
|
data = self.rfile.read(nbytes)
|
||||||
|
|
|
@ -475,6 +475,13 @@ class CGIHTTPServerTestCase(BaseTestCase):
|
||||||
self.assertEqual(('Hello World\n', 'text/html', 200),
|
self.assertEqual(('Hello World\n', 'text/html', 200),
|
||||||
(res.read(), res.getheader('Content-type'), res.status))
|
(res.read(), res.getheader('Content-type'), res.status))
|
||||||
|
|
||||||
|
def test_os_environ_is_not_altered(self):
|
||||||
|
signature = "Test CGI Server"
|
||||||
|
os.environ['SERVER_SOFTWARE'] = signature
|
||||||
|
res = self.request('/cgi-bin/file1.py')
|
||||||
|
self.assertEqual((b'Hello World\n', 'text/html', 200),
|
||||||
|
(res.read(), res.getheader('Content-type'), res.status))
|
||||||
|
self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
|
||||||
|
|
||||||
def test_main(verbose=None):
|
def test_main(verbose=None):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue