Commit db311894 authored by Evan Simpson's avatar Evan Simpson

Don't try to fix user HTML, and set content-length along with the body.

parent 2e2ab5d4
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
'''CGI Response Output formatter '''CGI Response Output formatter
$Id: HTTPResponse.py,v 1.38 2000/12/15 15:35:17 brian Exp $''' $Id: HTTPResponse.py,v 1.39 2000/12/15 16:14:01 evan Exp $'''
__version__='$Revision: 1.38 $'[11:-2] __version__='$Revision: 1.39 $'[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
...@@ -161,7 +161,7 @@ status_codes['redirect']=300 ...@@ -161,7 +161,7 @@ status_codes['redirect']=300
start_of_header_search=re.compile('(<head[^>]*>)', re.IGNORECASE).search start_of_header_search=re.compile('(<head[^>]*>)', re.IGNORECASE).search
end_of_header_search=regex.compile('</head>',regex.casefold).search #end_of_header_search=regex.compile('</head>',regex.casefold).search
accumulate_header={'set-cookie': 1}.has_key accumulate_header={'set-cookie': 1}.has_key
...@@ -315,6 +315,7 @@ class HTTPResponse(BaseResponse): ...@@ -315,6 +315,7 @@ class HTTPResponse(BaseResponse):
self.body=self._error_html(str(title), str(body)) self.body=self._error_html(str(title), str(body))
else: else:
self.body=str(body) self.body=str(body)
self.setHeader('content-length', len(self.body))
self.insertBase() self.insertBase()
return self return self
...@@ -694,20 +695,23 @@ class HTTPResponse(BaseResponse): ...@@ -694,20 +695,23 @@ class HTTPResponse(BaseResponse):
else: else:
c='text/plain' c='text/plain'
self.setHeader('content-type',c) self.setHeader('content-type',c)
else:
isHTML = split(headers.get('content-type', ''), # Don't try to fix user HTML!
';')[0] == 'text/html'
if isHTML and end_of_header_search(self.body) < 0: #else:
lhtml=html_search(body) # isHTML = split(headers.get('content-type', ''),
if lhtml >= 0: # ';')[0] == 'text/html'
lhtml=lhtml+6 #if isHTML and end_of_header_search(self.body) < 0:
body='%s<head></head>\n%s' % (body[:lhtml],body[lhtml:]) # lhtml=html_search(body)
elif contHTML: # if lhtml >= 0:
body='<html><head></head>\n' + body # lhtml=lhtml+6
else: # body='%s<head></head>\n%s' % (body[:lhtml],body[lhtml:])
body='<html><head></head>\n' + body + '\n</html>\n' # elif contHTML:
self.setBody(body) # body='<html><head></head>\n' + body
body=self.body # else:
# body='<html><head></head>\n' + body + '\n</html>\n'
# self.setBody(body)
# body=self.body
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'):
......
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