Skip to content

Commit

Permalink
Merge 45c9aca into 9577443
Browse files Browse the repository at this point in the history
  • Loading branch information
chaosk committed Mar 30, 2016
2 parents 9577443 + 45c9aca commit 22332ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
14 changes: 10 additions & 4 deletions errand_boy/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,16 @@ def recv_algo(self, connection, recv_func):

data += new_data

if CRLF in data:
split_data = data.split(CRLF)
lines.extend(split_data[:-1])
data = split_data[-1]
if not lines and CRLF in data:
try:
headers, body = data.split(CRLF + CRLF, 1)
except ValueError:
split_data = data.split(CRLF)
lines.extend(split_data[:-1])
data = split_data[-1]
else:
lines.extend((headers + CRLF).split(CRLF))
data = body

if lines and content_length is None:
for line in lines:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_unixsocket_transport_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest

import errand_boy
from errand_boy.constants import CRLF
from errand_boy.exceptions import SessionClosedError
from errand_boy.transports import base, unixsocket

Expand Down Expand Up @@ -47,3 +48,22 @@ def test_large_amount_of_data(self):
res_returncode = process.returncode

self.assertEqual(res_stdout, str_data)

def test_crlf_in_body(self):
transport = unixsocket.UNIXSocketTransport()

str_data = b'foo' + CRLF + b'bar'

with transport.get_session() as session:
foo = session.subprocess

process = foo.Popen(['cat'], stdin=foo.PIPE,
stdout=foo.PIPE,
stderr=foo.PIPE
)

res_stdout, res_stderr = process.communicate(str_data)

res_returncode = process.returncode

self.assertEqual(res_stdout, str_data)

0 comments on commit 22332ee

Please sign in to comment.