From 7049becdfe5fa16820fc7dd3da0866cf08464efd Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 15 Dec 2013 06:42:58 +0100 Subject: always return Content-Length: 0 if r is not set --- libpathod/language.py | 5 +++-- libpathod/pathoc.py | 12 ++++++------ libpathod/pathod.py | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'libpathod') diff --git a/libpathod/language.py b/libpathod/language.py index 5cce6fde..ed5e5f60 100644 --- a/libpathod/language.py +++ b/libpathod/language.py @@ -765,11 +765,12 @@ class _Message(object): def resolve(self, settings, request_host): tokens = self.tokens[:] if not self.raw: - if self.body and not utils.get_header("Content-Length", self.headers): + if not utils.get_header("Content-Length", self.headers): + length = 0 if not self.body else len(self.body.value.get_generator(settings)) tokens.append( Header( ValueLiteral("Content-Length"), - ValueLiteral(str(len(self.body.value.get_generator(settings)))), + ValueLiteral(str(length)), ) ) if request_host: diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 32707899..34dec94f 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -26,19 +26,19 @@ class Pathoc(tcp.TCPClient): self.ssl, self.sni = ssl, sni self.clientcert = clientcert - def http_connect(self, connect_to, wfile, rfile): - wfile.write( + def http_connect(self, connect_to): + self.wfile.write( 'CONNECT %s:%s HTTP/1.1\r\n'%tuple(connect_to) + '\r\n' ) - wfile.flush() - l = rfile.readline() + self.wfile.flush() + l = self.rfile.readline() if not l: raise PathocError("Proxy CONNECT failed") parsed = http.parse_response_line(l) if not parsed[1] == 200: raise PathocError("Proxy CONNECT failed: %s - %s"%(parsed[1], parsed[2])) - headers = http.read_headers(rfile) + headers = http.read_headers(self.rfile) def connect(self, connect_to=None): """ @@ -47,7 +47,7 @@ class Pathoc(tcp.TCPClient): """ tcp.TCPClient.connect(self) if connect_to: - self.http_connect(connect_to, self.wfile, self.rfile) + self.http_connect(connect_to) if self.ssl: try: self.convert_to_ssl(sni=self.sni, cert=self.clientcert) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 5fc1fd55..d925de24 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -123,8 +123,8 @@ class PathodHandler(tcp.BaseHandler): ) try: - content = http.read_http_body_request( - self.rfile, self.wfile, headers, httpversion, None + content = http.read_http_body( + self.rfile, headers, None, True ) except http.HttpError, s: s = str(s) -- cgit v1.2.3 From 8229c3884f88b140240694f9d714c179d5561b17 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 17 Dec 2013 14:32:41 +1300 Subject: Ability to specify SSL/TLS version --- libpathod/pathoc.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'libpathod') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 32707899..3e83db49 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -15,9 +15,15 @@ class Response: def __repr__(self): return "Response(%s - %s)"%(self.status_code, self.msg) +SSLVERSIONS = { + 1: tcp.TLSv1_METHOD, + 2: tcp.SSLv2_METHOD, + 3: tcp.SSLv3_METHOD, + 4: tcp.SSLv23_METHOD, +} class Pathoc(tcp.TCPClient): - def __init__(self, host, port, ssl=None, sni=None, clientcert=None): + def __init__(self, host, port, ssl=None, sni=None, sslversion=1, clientcert=None): tcp.TCPClient.__init__(self, host, port) self.settings = dict( staticdir = os.getcwd(), @@ -25,6 +31,7 @@ class Pathoc(tcp.TCPClient): ) self.ssl, self.sni = ssl, sni self.clientcert = clientcert + self.sslversion = SSLVERSIONS[sslversion] def http_connect(self, connect_to, wfile, rfile): wfile.write( @@ -50,7 +57,7 @@ class Pathoc(tcp.TCPClient): self.http_connect(connect_to, self.wfile, self.rfile) if self.ssl: try: - self.convert_to_ssl(sni=self.sni, cert=self.clientcert) + self.convert_to_ssl(sni=self.sni, cert=self.clientcert, method=self.sslversion) except tcp.NetLibError, v: raise PathocError(str(v)) -- cgit v1.2.3