Commit 7526deca authored by Andreas Jung's avatar Andreas Jung

Collector #348: decapitate() now recognizes both \r\n and \n\n

to be compliant with the HTTP RFC
parent a5ab9f75
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""DTML Method objects.""" """DTML Method objects."""
__version__='$Revision: 1.77 $'[11:-2] __version__='$Revision: 1.78 $'[11:-2]
import History import History
from Globals import HTML, DTMLFile, MessageDialog from Globals import HTML, DTMLFile, MessageDialog
...@@ -349,28 +349,40 @@ import re ...@@ -349,28 +349,40 @@ import re
token = "[a-zA-Z0-9!#$%&'*+\-.\\\\^_`|~]+" token = "[a-zA-Z0-9!#$%&'*+\-.\\\\^_`|~]+"
hdr_start = re.compile(r'(%s):(.*)' % token).match hdr_start = re.compile(r'(%s):(.*)' % token).match
def decapitate(html, RESPONSE=None): def decapitate(html, RESPONSE=None):
headers = [] headers = []
spos = 0 spos = 0
eolen = 1
while 1: while 1:
m = hdr_start(html, spos) m = hdr_start(html, spos)
if not m: if not m:
if html[spos:spos+2] == '\r\n':
eolen = 2
break
if html[spos:spos+1] == '\n': if html[spos:spos+1] == '\n':
eolen = 1
break break
return html return html
header = list(m.groups()) header = list(m.groups())
headers.append(header) headers.append(header)
spos = m.end() + 1 spos = m.end() + 1
while spos < len(html) and html[spos] in ' \t': while spos < len(html) and html[spos] in ' \t':
eol = html.find( '\n', spos) eol = find(html, '\r\n', spos)
if eol < 0: return html if eol <> -1:
header.append(html[spos:eol].strip()) eolen = 2
spos = eol + 1 else:
eol = find(html, '\n', spos)
if eol < 0: return html
eolen = 1
header.append(strip(html[spos:eol]))
spos = eol + eolen
if RESPONSE is not None: if RESPONSE is not None:
for header in headers: for header in headers:
hkey = header.pop(0) hkey = header.pop(0)
RESPONSE.setHeader(hkey, ' '.join(header).strip()) RESPONSE.setHeader(hkey, ' '.join(header).strip())
return html[spos + 1:] return html[spos + eolen:]
default_dm_html="""<dtml-var standard_html_header> default_dm_html="""<dtml-var standard_html_header>
<h2><dtml-var title_or_id> <dtml-var document_title></h2> <h2><dtml-var title_or_id> <dtml-var document_title></h2>
......
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