From 0cb0f0e448372603f11de94637b2f7518f686869 Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Fri, 13 Dec 2013 19:36:22 -0800 Subject: [PATCH] ensure request headers always use \r\n (some servers barf if not, e.g. http://cleftomaniacsnyu.wix.com --- warcprox/warcprox.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/warcprox/warcprox.py b/warcprox/warcprox.py index 378ef95..f7ef1cf 100644 --- a/warcprox/warcprox.py +++ b/warcprox/warcprox.py @@ -398,15 +398,20 @@ class WarcProxyHandler(MitmProxyHandler): def _proxy_request(self): # Build request - req = '{} {} {}\r\n'.format(self.command, self.path, self.request_version).encode('utf-8') + req_str = '{} {} {}\r\n'.format(self.command, self.path, self.request_version) # Add headers to the request - req += str(self.headers).encode('utf-8') + b'\r\n' + # XXX in at least python3.3 str(self.headers) uses \n not \r\n :( + req_str += '\r\n'.join('{}: {}'.format(k,v) for (k,v) in self.headers.items()) + + req = req_str.encode('utf-8') + b'\r\n\r\n' # Append message body if present to the request if 'Content-Length' in self.headers: req += self.rfile.read(int(self.headers['Content-Length'])) + self.logger.debug('req={}'.format(repr(req))) + # Send it down the pipe! self._proxy_sock.sendall(req)