パスに応じて接続ホストを変更しようとしている、 の問題、context
フローの作成時に作成されるはずですが、リクエスト間で共有されます。だから私はここで負けました、これは私が試したことです
import re
import os
os.environ['PAGER'] = 'cat'
from libmproxy.models import HTTPResponse
from netlib.http import Headers
from netlib.tcp import Address
def request(context, flow):
# flow.request.path
context.log("server %s " % repr(flow.server_conn) ,"info");
if flow.request.host.endswith("google.com"):
if re.match(flow.request.path, "/"):
context.address = "10.0.0.15";
else:
context.address = "google.com"
def serverconnect(context, server_conn):
if hasattr(context, 'address'):
context.log("server changed from %s" % (repr(server_conn)) ,"info");
server_conn.address = Address(address=(context.address, server_conn.address.port))
context.log("server changed to %s" % (repr(server_conn)) ,"info");
else:
context.log("server NOT changed %s" % repr(server_conn),"info");
重要な注意点:
HOST:
http 要求ヘッダーを変更する必要はありません。