Пример #1
0
 def handle_request(self, request: HttpParser) -> None:
     nspid = self.nspid
     with netns.NetNS(nspid=nspid):
         with socket_connection(self.upstream) as conn:
             conn.send(request.build())
             data = conn.recv(DEFAULT_BUFFER_SIZE)
             while (data):
                 self.client.queue(memoryview(data))
                 data = conn.recv(DEFAULT_BUFFER_SIZE)
Пример #2
0
 def test_with_proxy(self) -> None:
     """Makes a HTTP request to in-build web server via proxy server."""
     assert self.PROXY
     with socket_connection(('localhost', self.PROXY.flags.port)) as conn:
         conn.send(
             build_http_request(
                 httpMethods.GET,
                 b'http://localhost:%d/' % self.PROXY.flags.port,
                 headers={
                     b'Host': b'localhost:%d' % self.PROXY.flags.port,
                 },
             ), )
         response = conn.recv(DEFAULT_CLIENT_RECVBUF_SIZE)
     self.assertEqual(
         response,
         NOT_FOUND_RESPONSE_PKT.tobytes(),
     )
Пример #3
0
 def test_with_proxy(self) -> None:
     """Makes a HTTP request to in-build web server via proxy server."""
     with socket_connection(('localhost', self.PROXY_PORT)) as conn:
         conn.send(
             build_http_request(httpMethods.GET,
                                b'http://localhost:%d/' % self.PROXY_PORT,
                                headers={
                                    b'Host':
                                    b'localhost:%d' % self.PROXY_PORT,
                                }))
         response = conn.recv(DEFAULT_CLIENT_RECVBUF_SIZE)
     self.assertEqual(
         response,
         build_http_response(httpStatusCodes.NOT_FOUND,
                             reason=b'NOT FOUND',
                             headers={
                                 b'Server': PROXY_AGENT_HEADER_VALUE,
                                 b'Connection': b'close'
                             }))
# -*- coding: utf-8 -*-
"""
    proxy.py
    ~~~~~~~~
    ⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
    Network monitoring, controls & Application development, testing, debugging.

    :copyright: (c) 2013-present by Abhinav Singh and contributors.
    :license: BSD, see LICENSE for more details.
"""
from proxy.common.utils import socket_connection
from proxy.common.constants import DEFAULT_BUFFER_SIZE

if __name__ == '__main__':
    with socket_connection(('::', 12345)) as client:
        while True:
            client.send(b'hello')
            data = client.recv(DEFAULT_BUFFER_SIZE)
            if data is None:
                break
            print(data)
Пример #5
0
 def test_context_manager(self,
                          mock_new_socket_connection: mock.Mock) -> None:
     with socket_connection(self.addr_ipv4) as conn:
         self.assertEqual(conn, mock_new_socket_connection.return_value)
Пример #6
0
# -*- coding: utf-8 -*-
"""
    proxy.py
    ~~~~~~~~
    ⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
    Network monitoring, controls & Application development, testing, debugging.

    :copyright: (c) 2013-present by Abhinav Singh and contributors.
    :license: BSD, see LICENSE for more details.
"""
import logging

from proxy.common.utils import socket_connection
from proxy.common.constants import DEFAULT_LOG_FORMAT, DEFAULT_BUFFER_SIZE

logging.basicConfig(level=logging.INFO, format=DEFAULT_LOG_FORMAT)

logger = logging.getLogger(__name__)

if __name__ == '__main__':
    with socket_connection(('127.0.0.1', 12345)) as client:
        while True:
            client.send(b'hello')
            data = client.recv(DEFAULT_BUFFER_SIZE)
            if data is None:
                break
            logger.info(data)