Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a28b3e6

Browse files
committed
Patch #727483: Add AUTH_TYPE and REMOTE_USER.
1 parent 061f132 commit a28b3e6

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Lib/CGIHTTPServer.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,21 @@ def run_cgi(self):
153153
if host != self.client_address[0]:
154154
env['REMOTE_HOST'] = host
155155
env['REMOTE_ADDR'] = self.client_address[0]
156-
# XXX AUTH_TYPE
157-
# XXX REMOTE_USER
156+
authorization = self.headers.getheader("authorization")
157+
if authorization:
158+
authorization = authorization.split()
159+
if len(authorization) == 2:
160+
import base64, binascii
161+
env['AUTH_TYPE'] = authorization[0]
162+
if authorization[0].lower() == "basic":
163+
try:
164+
authorization = base64.decodestring(authorization[1])
165+
except binascii.Error:
166+
pass
167+
else:
168+
authorization = authorization.split(':')
169+
if len(authorization) == 2:
170+
env['REMOTE_USER'] = authorization[0]
158171
# XXX REMOTE_IDENT
159172
if self.headers.typeheader is None:
160173
env['CONTENT_TYPE'] = self.headers.type

0 commit comments

Comments
 (0)