Skip to content

Commit

Permalink
instead of split on CRLFCRLF and then on LFLF, check which one appear…
Browse files Browse the repository at this point in the history
…s first -- bug if the body contains CRLFCRLF but the headers-body is separated by LFLF
  • Loading branch information
theintencity committed Oct 8, 2012
1 parent f7e09f2 commit c9a3e27
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/std/rfc3261.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,19 @@ def _parse(self, value):
# 8. Content-Length if present must match the length of body.
# 9. mandatory headers are To, From, Call-ID and CSeq.
# 10. syntax for top Via header and fields: ttl, maddr, received, branch.
try: firstheaders, body = value.split('\r\n\r\n', 1)
except ValueError: # may be \n\n
try: firstheaders, body = value.split('\n\n', 1)
except ValueError: firstheaders, body = value, '' # assume no body
try: firstline, headers = firstheaders.split('\r\n', 1)
except ValueError: firstline, headers = firstheaders.split('\n', 1)
indexCRLFCRLF, indexLFLF = value.find('\r\n\r\n'), value.find('\n\n')
firstheaders = body = ''
if indexCRLFCRLF >= 0 and indexLFLF >= 0:
if indexCRLFCRLF < indexLFLF: indexLFLF = -1
else: indexCRLFCRLF = -1
if indexCRLFCRLF >= 0:
firstheaders, body = value[:indexCRLFCRLF], value[indexCRLFCRLF+4:]
elif indexLFLF >= 0:
firstheaders, body = value[:indexLFLF], value[indexLFLF+2:]
else:
firstheaders, body = value, '' # assume no body
firstline, headers = firstheaders.split('\n', 1)
if firstline[-1] == '\r': firstline = firstline[:-1]
a, b, c = firstline.split(' ', 2)
try: # try as response
self.response, self.responsetext, self.protocol = int(b), c, a # throws error if b is not int.
Expand Down

0 comments on commit c9a3e27

Please sign in to comment.