From 78ae3e4a0009d7bb2f2f7f53df2d622fc12d05dc Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 8 Jul 2015 09:34:52 +0200 Subject: use netlib.http_semantics for generic data --- libpathod/pathoc.py | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) (limited to 'libpathod/pathoc.py') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 39d3c3d6..7f7cbb87 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -11,7 +11,7 @@ import threading import OpenSSL.crypto -from netlib import tcp, http, http2, certutils, websockets, socks +from netlib import tcp, http, http2, http_semantics, certutils, websockets, socks import language.http import language.websockets @@ -66,25 +66,6 @@ class SSLInfo(object): return "\n".join(parts) -class Response(object): - - def __init__( - self, - httpversion, - status_code, - msg, - headers, - content, - sslinfo - ): - self.httpversion, self.status_code = httpversion, status_code - self.msg = msg - self.headers, self.content = headers, content - self.sslinfo = sslinfo - - def __repr__(self): - return "Response(%s - %s)" % (self.status_code, self.msg) - class WebsocketFrameReader(threading.Thread): @@ -429,17 +410,14 @@ class Pathoc(tcp.TCPClient): if self.use_http2: status_code, headers, body = self.protocol.read_response() - resp = Response("HTTP/2", status_code, "", headers, body, self.sslinfo) + resp = http_semantics.Response("HTTP/2", status_code, "", headers, body, self.sslinfo) else: - resp = list( - http.read_response( + resp = http.read_response( self.rfile, req["method"], None ) - ) - resp.append(self.sslinfo) - resp = Response(*resp) + resp.sslinfo = self.sslinfo except http.HttpError as v: lg("Invalid server response: %s" % v) raise -- cgit v1.2.3 From 2b0465dbb93dd4bf0d6db366db597c05e92121d8 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 15 Jul 2015 22:04:25 +0200 Subject: use new netlib module names --- libpathod/pathoc.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'libpathod/pathoc.py') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 7f7cbb87..89b0e0c9 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -11,7 +11,8 @@ import threading import OpenSSL.crypto -from netlib import tcp, http, http2, http_semantics, certutils, websockets, socks +from netlib import tcp, http, certutils, websockets, socks +from netlib.http import http1, http2 import language.http import language.websockets @@ -228,12 +229,12 @@ class Pathoc(tcp.TCPClient): l = self.rfile.readline() if not l: raise PathocError("Proxy CONNECT failed") - parsed = http.parse_response_line(l) + parsed = http.http1.parse_response_line(l) if not parsed[1] == 200: raise PathocError( "Proxy CONNECT failed: %s - %s" % (parsed[1], parsed[2]) ) - http.read_headers(self.rfile) + http.http1.read_headers(self.rfile) def socks_connect(self, connect_to): try: @@ -410,9 +411,9 @@ class Pathoc(tcp.TCPClient): if self.use_http2: status_code, headers, body = self.protocol.read_response() - resp = http_semantics.Response("HTTP/2", status_code, "", headers, body, self.sslinfo) + resp = http.Response("HTTP/2", status_code, "", headers, body, self.sslinfo) else: - resp = http.read_response( + resp = http.http1.read_response( self.rfile, req["method"], None -- cgit v1.2.3 From 032f8b2985a7c5f89d2dde0992e4f356bf58fcaa Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 16 Jul 2015 22:57:20 +0200 Subject: use common interface for HTTP/1 and HTTP/2 --- libpathod/pathoc.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'libpathod/pathoc.py') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 89b0e0c9..ba15e630 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -209,8 +209,7 @@ class Pathoc(tcp.TCPClient): ) self.protocol = http2.HTTP2Protocol(self, dump_frames=self.http2_framedump) else: - # TODO: create HTTP or Websockets protocol - self.protocol = None + self.protocol = http1.HTTP1Protocol(self) self.settings = language.Settings( is_client=True, @@ -409,16 +408,8 @@ class Pathoc(tcp.TCPClient): req = language.serve(r, self.wfile, self.settings) self.wfile.flush() - if self.use_http2: - status_code, headers, body = self.protocol.read_response() - resp = http.Response("HTTP/2", status_code, "", headers, body, self.sslinfo) - else: - resp = http.http1.read_response( - self.rfile, - req["method"], - None - ) - resp.sslinfo = self.sslinfo + resp = self.protocol.read_response(req["method"], None) + resp.sslinfo = self.sslinfo except http.HttpError as v: lg("Invalid server response: %s" % v) raise -- cgit v1.2.3 From caaac5cd5a48d2bd1e50f0ff88c9d73a20ec9aa6 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 16 Jul 2015 22:57:45 +0200 Subject: inline log method --- libpathod/pathoc.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libpathod/pathoc.py') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index ba15e630..b7802daa 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -314,11 +314,6 @@ class Pathoc(tcp.TCPClient): if self.timeout: self.settimeout(self.timeout) - def _resp_summary(self, resp): - return "<< %s %s: %s bytes" % ( - resp.status_code, utils.xrepr(resp.msg), len(resp.content) - ) - def stop(self): if self.ws_framereader: self.ws_framereader.terminate.put(None) @@ -421,7 +416,9 @@ class Pathoc(tcp.TCPClient): raise finally: if resp: - lg(self._resp_summary(resp)) + lg("<< %s %s: %s bytes" % ( + resp.status_code, utils.xrepr(resp.msg), len(resp.content) + )) if resp.status_code in self.ignorecodes: lg.suppress() return resp -- cgit v1.2.3 From 6d5a3da9294d5bc6758ded173729042573c9fe5f Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 18 Jul 2015 15:54:29 +0200 Subject: use new HTTP/1 protocol --- libpathod/pathoc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libpathod/pathoc.py') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index b7802daa..c1bca07f 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -228,12 +228,12 @@ class Pathoc(tcp.TCPClient): l = self.rfile.readline() if not l: raise PathocError("Proxy CONNECT failed") - parsed = http.http1.parse_response_line(l) + parsed = self.protocol.parse_response_line(l) if not parsed[1] == 200: raise PathocError( "Proxy CONNECT failed: %s - %s" % (parsed[1], parsed[2]) ) - http.http1.read_headers(self.rfile) + self.protocol.read_headers() def socks_connect(self, connect_to): try: -- cgit v1.2.3 From 11ac387df2a49d132a08648b6cb5121224924c9d Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 19 Jul 2015 18:17:09 +0200 Subject: rename content -> body --- libpathod/pathoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libpathod/pathoc.py') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index c1bca07f..e93e6208 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -417,7 +417,7 @@ class Pathoc(tcp.TCPClient): finally: if resp: lg("<< %s %s: %s bytes" % ( - resp.status_code, utils.xrepr(resp.msg), len(resp.content) + resp.status_code, utils.xrepr(resp.msg), len(resp.body) )) if resp.status_code in self.ignorecodes: lg.suppress() -- cgit v1.2.3