Commit 948c6ff3 authored by 's avatar

Merged bugfix from 2.2 branch

parent 3c7c83e9
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
'''CGI Response Output formatter '''CGI Response Output formatter
$Id: HTTPResponse.py,v 1.33 2000/08/08 16:06:00 brian Exp $''' $Id: HTTPResponse.py,v 1.34 2000/08/16 19:30:04 brian Exp $'''
__version__='$Revision: 1.33 $'[11:-2] __version__='$Revision: 1.34 $'[11:-2]
import string, types, sys, regex, re import string, types, sys, regex, re
from string import find, rfind, lower, upper, strip, split, join, translate from string import find, rfind, lower, upper, strip, split, join, translate
...@@ -328,8 +328,9 @@ class HTTPResponse(BaseResponse): ...@@ -328,8 +328,9 @@ class HTTPResponse(BaseResponse):
base_re_search=regex.compile('\(<base[\0- ]+[^>]+>\)', base_re_search=regex.compile('\(<base[\0- ]+[^>]+>\)',
regex.casefold).search regex.casefold).search
): ):
# Only insert a base tag if content appears to be html. # Only insert a base tag if content appears to be html.
content_type = self.headers.get('content-type', '')[:9] content_type = split(self.headers.get('content-type', ''), ';')[0]
if content_type and (content_type != 'text/html'): if content_type and (content_type != 'text/html'):
return return
...@@ -638,7 +639,7 @@ class HTTPResponse(BaseResponse): ...@@ -638,7 +639,7 @@ class HTTPResponse(BaseResponse):
self._traceback(t,v,tb)), self._traceback(t,v,tb)),
is_error=1) is_error=1)
elif lower(strip(b))[:6]=='<html>' or lower(strip(b))[:14]=='<!doctype html': elif lower(strip(b)[:6])=='<html>' or lower(strip(b)[:14])=='<!doctype html':
# error is an HTML document, not just a snippet of html # error is an HTML document, not just a snippet of html
tb=self.setBody(b + self._traceback(t,'(see above)',tb), tb=self.setBody(b + self._traceback(t,'(see above)',tb),
is_error=1) is_error=1)
...@@ -682,7 +683,7 @@ class HTTPResponse(BaseResponse): ...@@ -682,7 +683,7 @@ class HTTPResponse(BaseResponse):
headers=self.headers headers=self.headers
body=self.body body=self.body
if body: if body:
isHTML=self.isHTML(body) isHTML=contHTML=self.isHTML(body)
if not headers.has_key('content-type'): if not headers.has_key('content-type'):
if isHTML: if isHTML:
c='text/html' c='text/html'
...@@ -690,21 +691,20 @@ class HTTPResponse(BaseResponse): ...@@ -690,21 +691,20 @@ class HTTPResponse(BaseResponse):
c='text/plain' c='text/plain'
self.setHeader('content-type',c) self.setHeader('content-type',c)
else: else:
isHTML = headers['content-type'][:9] == 'text/html' isHTML = split(headers.get('content-type', ''),
';')[0] == 'text/html'
if isHTML and end_of_header_search(self.body) < 0: if isHTML and end_of_header_search(self.body) < 0:
lhtml=html_search(body) lhtml=html_search(body)
if lhtml >= 0: if lhtml >= 0:
lhtml=lhtml+6 lhtml=lhtml+6
body='%s<head></head>\n%s' % (body[:lhtml],body[lhtml:]) body='%s<head></head>\n%s' % (body[:lhtml],body[lhtml:])
else: elif contHTML:
body='<html><head></head>\n' + body body='<html><head></head>\n' + body
else:
body='<html><head></head>\n' + body + '\n</html>\n'
self.setBody(body) self.setBody(body)
body=self.body body=self.body
# if not headers.has_key('content-type') and self.status == 200:
# self.setStatus('nocontent')
if not headers.has_key('content-length') and \ if not headers.has_key('content-length') and \
not headers.has_key('transfer-encoding'): not headers.has_key('transfer-encoding'):
self.setHeader('content-length',len(body)) self.setHeader('content-length',len(body))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment