Skip to content

Commit 4a2ebc9

Browse files
committed
Added Try/Except block around header delimiter
Headers should end with a carriage return/line feed at the end of each line and then a blank line (with a CRLF) to end the header. In some cases, for example a 406 reponse, the header will not have the blank line and instead the server will close the connection. In this case the code raises a ValueError exception which is not very helpfully. Inserting this try/except block adds clarity to what failed.
1 parent ac20580 commit 4a2ebc9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

__pycache__/rtsp.cpython-36.pyc

183 Bytes
Binary file not shown.

rtsp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ def recv_msg(self):
180180
msg = ''
181181
if self.cache():
182182
tmp = self.cache()
183-
(msg, tmp) = tmp.split(HEADER_END_STR, 1)
183+
try:
184+
(msg, tmp) = tmp.split(HEADER_END_STR, 1)
185+
except ValueError as e:
186+
self._callback(self._get_time_str() + '\n' + tmp)
187+
raise RTSPError('Response did not contain double CRLF')
184188
content_length = self._get_content_length(msg)
185189
msg += HEADER_END_STR + tmp[:content_length]
186190
self.set_cache(tmp[content_length:])

0 commit comments

Comments
 (0)