mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-29 12:45:00 +08:00
The final piece: netlib -> mitproxy.net
This commit is contained in:
@@ -2,12 +2,12 @@ import abc
|
||||
|
||||
import pyparsing as pp
|
||||
|
||||
from netlib.http import url
|
||||
import netlib.websockets
|
||||
from netlib.http import status_codes, user_agents
|
||||
from mitmproxy.net.http import url
|
||||
import mitmproxy.net.websockets
|
||||
from mitmproxy.net.http import status_codes, user_agents
|
||||
from . import base, exceptions, actions, message
|
||||
|
||||
# TODO: use netlib.semantics.protocol assemble method,
|
||||
# TODO: use mitmproxy.net.semantics.protocol assemble method,
|
||||
# instead of duplicating the HTTP on-the-wire representation here.
|
||||
# see http2 language for an example
|
||||
|
||||
@@ -198,7 +198,7 @@ class Response(_HTTPMessage):
|
||||
1,
|
||||
StatusCode(101)
|
||||
)
|
||||
headers = netlib.websockets.server_handshake_headers(
|
||||
headers = mitmproxy.net.websockets.server_handshake_headers(
|
||||
settings.websocket_key
|
||||
)
|
||||
for i in headers.fields:
|
||||
@@ -310,7 +310,7 @@ class Request(_HTTPMessage):
|
||||
1,
|
||||
Method("get")
|
||||
)
|
||||
for i in netlib.websockets.client_handshake_headers().fields:
|
||||
for i in mitmproxy.net.websockets.client_handshake_headers().fields:
|
||||
if not get_header(i[0], self.headers):
|
||||
tokens.append(
|
||||
Header(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pyparsing as pp
|
||||
|
||||
from netlib import http
|
||||
from netlib.http import user_agents, Headers
|
||||
from mitmproxy.net import http
|
||||
from mitmproxy.net.http import user_agents, Headers
|
||||
from . import base, message
|
||||
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import random
|
||||
import string
|
||||
import netlib.websockets
|
||||
import mitmproxy.net.websockets
|
||||
from mitmproxy.utils import strutils
|
||||
import pyparsing as pp
|
||||
from . import base, generators, actions, message
|
||||
@@ -14,12 +14,12 @@ class WF(base.CaselessLiteral):
|
||||
|
||||
class OpCode(base.IntField):
|
||||
names = {
|
||||
"continue": netlib.websockets.OPCODE.CONTINUE,
|
||||
"text": netlib.websockets.OPCODE.TEXT,
|
||||
"binary": netlib.websockets.OPCODE.BINARY,
|
||||
"close": netlib.websockets.OPCODE.CLOSE,
|
||||
"ping": netlib.websockets.OPCODE.PING,
|
||||
"pong": netlib.websockets.OPCODE.PONG,
|
||||
"continue": mitmproxy.net.websockets.OPCODE.CONTINUE,
|
||||
"text": mitmproxy.net.websockets.OPCODE.TEXT,
|
||||
"binary": mitmproxy.net.websockets.OPCODE.BINARY,
|
||||
"close": mitmproxy.net.websockets.OPCODE.CLOSE,
|
||||
"ping": mitmproxy.net.websockets.OPCODE.PING,
|
||||
"pong": mitmproxy.net.websockets.OPCODE.PONG,
|
||||
}
|
||||
max = 15
|
||||
preamble = "c"
|
||||
@@ -215,11 +215,11 @@ class WebsocketFrame(message.Message):
|
||||
v = getattr(self, i, None)
|
||||
if v is not None:
|
||||
frameparts[i] = v.value
|
||||
frame = netlib.websockets.FrameHeader(**frameparts)
|
||||
frame = mitmproxy.net.websockets.FrameHeader(**frameparts)
|
||||
vals = [bytes(frame)]
|
||||
if bodygen:
|
||||
if frame.masking_key and not self.rawbody:
|
||||
masker = netlib.websockets.Masker(frame.masking_key)
|
||||
masker = mitmproxy.net.websockets.Masker(frame.masking_key)
|
||||
vals.append(
|
||||
generators.TransformGenerator(
|
||||
bodygen,
|
||||
|
||||
@@ -13,12 +13,12 @@ import logging
|
||||
|
||||
from mitmproxy.test.tutils import treq
|
||||
from mitmproxy.utils import strutils
|
||||
from netlib import tcp
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy import certs
|
||||
from netlib import websockets
|
||||
from netlib import socks
|
||||
from mitmproxy.net import websockets
|
||||
from mitmproxy.net import socks
|
||||
from mitmproxy import exceptions
|
||||
from netlib.http import http1
|
||||
from mitmproxy.net.http import http1
|
||||
from mitmproxy.types import basethread
|
||||
|
||||
from pathod import log
|
||||
|
||||
@@ -3,9 +3,9 @@ import argparse
|
||||
import os
|
||||
import os.path
|
||||
|
||||
from netlib import tcp
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy import version
|
||||
from netlib.http import user_agents
|
||||
from mitmproxy.net.http import user_agents
|
||||
from . import pathoc, language
|
||||
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import os
|
||||
import sys
|
||||
import threading
|
||||
|
||||
from netlib import tcp
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy import certs as mcerts
|
||||
from netlib import websockets
|
||||
from mitmproxy.net import websockets
|
||||
from mitmproxy import version
|
||||
|
||||
import urllib
|
||||
|
||||
@@ -4,7 +4,7 @@ import os
|
||||
import os.path
|
||||
import re
|
||||
|
||||
from netlib import tcp
|
||||
from mitmproxy.net import tcp
|
||||
from mitmproxy.utils import human
|
||||
from mitmproxy import version
|
||||
from . import pathod
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from mitmproxy import version
|
||||
from mitmproxy import exceptions
|
||||
from netlib.http import http1
|
||||
from mitmproxy.net.http import http1
|
||||
from .. import language
|
||||
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import time
|
||||
import hyperframe.frame
|
||||
from hpack.hpack import Encoder, Decoder
|
||||
|
||||
from netlib.http import http2
|
||||
import netlib.http.headers
|
||||
import netlib.http.response
|
||||
import netlib.http.request
|
||||
from mitmproxy.net.http import http2
|
||||
import mitmproxy.net.http.headers
|
||||
import mitmproxy.net.http.response
|
||||
import mitmproxy.net.http.request
|
||||
from mitmproxy.types import bidi
|
||||
|
||||
from .. import language
|
||||
@@ -100,7 +100,7 @@ class HTTP2StateProtocol:
|
||||
|
||||
first_line_format, method, scheme, host, port, path = http2.parse_headers(headers)
|
||||
|
||||
request = netlib.http.request.Request(
|
||||
request = mitmproxy.net.http.request.Request(
|
||||
first_line_format,
|
||||
method,
|
||||
scheme,
|
||||
@@ -148,7 +148,7 @@ class HTTP2StateProtocol:
|
||||
else:
|
||||
timestamp_end = None
|
||||
|
||||
response = netlib.http.response.Response(
|
||||
response = mitmproxy.net.http.response.Response(
|
||||
b"HTTP/2.0",
|
||||
int(headers.get(':status', 502)),
|
||||
b'',
|
||||
@@ -162,15 +162,15 @@ class HTTP2StateProtocol:
|
||||
return response
|
||||
|
||||
def assemble(self, message):
|
||||
if isinstance(message, netlib.http.request.Request):
|
||||
if isinstance(message, mitmproxy.net.http.request.Request):
|
||||
return self.assemble_request(message)
|
||||
elif isinstance(message, netlib.http.response.Response):
|
||||
elif isinstance(message, mitmproxy.net.http.response.Response):
|
||||
return self.assemble_response(message)
|
||||
else:
|
||||
raise ValueError("HTTP message not supported.")
|
||||
|
||||
def assemble_request(self, request):
|
||||
assert isinstance(request, netlib.http.request.Request)
|
||||
assert isinstance(request, mitmproxy.net.http.request.Request)
|
||||
|
||||
authority = self.tcp_handler.sni if self.tcp_handler.sni else self.tcp_handler.address.host
|
||||
if self.tcp_handler.address.port != 443:
|
||||
@@ -194,7 +194,7 @@ class HTTP2StateProtocol:
|
||||
self._create_body(request.body, stream_id)))
|
||||
|
||||
def assemble_response(self, response):
|
||||
assert isinstance(response, netlib.http.response.Response)
|
||||
assert isinstance(response, mitmproxy.net.http.response.Response)
|
||||
|
||||
headers = response.headers.copy()
|
||||
|
||||
@@ -394,7 +394,7 @@ class HTTP2StateProtocol:
|
||||
else:
|
||||
self._handle_unexpected_frame(frm)
|
||||
|
||||
headers = netlib.http.headers.Headers(
|
||||
headers = mitmproxy.net.http.headers.Headers(
|
||||
[[k, v] for k, v in self.decoder.decode(header_blocks, raw=True)]
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import time
|
||||
|
||||
from netlib import websockets
|
||||
from mitmproxy.net import websockets
|
||||
from pathod import language
|
||||
from mitmproxy import exceptions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user