diff --git a/.github/workflows/test-brew.yml b/.github/workflows/test-brew.yml index ff9b992c..e6afe49d 100644 --- a/.github/workflows/test-brew.yml +++ b/.github/workflows/test-brew.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v1 with: - python-version: ${{ matrix.python }}-dev + python-version: ${{ matrix.python }} - name: Brew run: | brew install ./helper/homebrew/develop/proxy.rb diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml index 7e1d4335..e6231865 100644 --- a/.github/workflows/test-docker.yml +++ b/.github/workflows/test-docker.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v1 with: - python-version: ${{ matrix.python }}-dev + python-version: ${{ matrix.python }} - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/test-library.yml b/.github/workflows/test-library.yml index 65059eca..90684853 100644 --- a/.github/workflows/test-library.yml +++ b/.github/workflows/test-library.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [macOS, ubuntu, windows] - python: [3.5, 3.6, 3.7, 3.8] + python: [3.6, 3.7, 3.8] max-parallel: 4 fail-fast: false steps: @@ -17,7 +17,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v1 with: - python-version: ${{ matrix.python }}-dev + python-version: ${{ matrix.python }} - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/README.md b/README.md index 8ece6895..6ed79cf3 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ [![Contributions Welcome](https://img.shields.io/static/v1?label=contributions&message=welcome%20%F0%9F%91%8D&color=green)](https://github.com/abhinavsingh/proxy.py/issues) [![Gitter](https://badges.gitter.im/proxy-py/community.svg)](https://gitter.im/proxy-py/community) -[![Python 3.5](https://img.shields.io/static/v1?label=Python&message=3.5%20%7C%203.6%20%7C%203.7%20%7C%203.8&color=blue)](https://www.python.org/) +[![Python 3.x](https://img.shields.io/static/v1?label=Python&message=3.6%20%7C%203.7%20%7C%203.8&color=blue)](https://www.python.org/) [![Checked with mypy](https://img.shields.io/static/v1?label=MyPy&message=checked&color=blue)](http://mypy-lang.org/) [![Become a Backer](https://opencollective.com/proxypy/tiers/backer.svg?avatarHeight=72)](https://opencollective.com/proxypy) diff --git a/proxy/benchmark/__init__.py b/proxy/benchmark/__init__.py deleted file mode 100644 index 8095cf95..00000000 --- a/proxy/benchmark/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python -# -*- 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. -""" diff --git a/proxy/benchmark/benchmark.py b/proxy/benchmark/benchmark.py deleted file mode 100644 index c12f74b4..00000000 --- a/proxy/benchmark/benchmark.py +++ /dev/null @@ -1,128 +0,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 asyncio -import time -from typing import List, Tuple - -from ..common.constants import DEFAULT_BUFFER_SIZE -from ..common.utils import build_http_request -from ..http.methods import httpMethods -from ..http.parser import httpParserStates, httpParserTypes, HttpParser - -__homepage__ = 'https://github.com/abhinavsingh/proxy.py' - -DEFAULT_N = 1 - - -class Benchmark: - - def __init__(self, n: int = DEFAULT_N) -> None: - self.n = n - self.clients: List[Tuple[asyncio.StreamReader, - asyncio.StreamWriter]] = [] - - async def open_connections(self) -> None: - for _ in range(self.n): - self.clients.append(await asyncio.open_connection('::', 8899)) - print('Opened ' + str(self.n) + ' connections') - - @staticmethod - async def send(writer: asyncio.StreamWriter) -> None: - try: - while True: - writer.write(build_http_request( - httpMethods.GET, b'/' - )) - await asyncio.sleep(0.01) - except KeyboardInterrupt: - pass - - @staticmethod - def parse_pipeline_response(response: HttpParser, raw: bytes, counter: int = 0) -> \ - Tuple[HttpParser, int]: - response.parse(raw) - if response.state != httpParserStates.COMPLETE: - # Need more data - return response, counter - - if response.buffer == b'': - # No more buffer left to parse - return response, counter + 1 - - # For pipelined requests we may have pending buffer, try parse them as - # responses - pipelined_response = HttpParser(httpParserTypes.RESPONSE_PARSER) - return Benchmark.parse_pipeline_response( - pipelined_response, response.buffer, counter + 1) - - @staticmethod - async def recv(idd: int, reader: asyncio.StreamReader) -> None: - print_every = 1000 - last_print = time.time() - num_completed_requests: int = 0 - response = HttpParser(httpParserTypes.RESPONSE_PARSER) - try: - while True: - raw = await reader.read(DEFAULT_BUFFER_SIZE) - response, total_parsed = Benchmark.parse_pipeline_response( - response, raw) - if response.state == httpParserStates.COMPLETE: - response = HttpParser(httpParserTypes.RESPONSE_PARSER) - if total_parsed > 0: - num_completed_requests += total_parsed - # print('total parsed %d' % total_parsed) - if num_completed_requests % print_every == 0: - now = time.time() - print('[%d] Completed last %d requests in %.2f secs' % - (idd, print_every, now - last_print)) - last_print = now - except KeyboardInterrupt: - pass - - async def close_connections(self) -> None: - for reader, writer in self.clients: - writer.close() - await writer.wait_closed() - print('Closed ' + str(self.n) + ' connections') - - async def run(self) -> None: - try: - await self.open_connections() - print('Exchanging request / response packets') - readers = [] - writers = [] - idd = 0 - for reader, writer in self.clients: - readers.append( - asyncio.create_task( - self.recv(idd, reader) - ) - ) - writers.append( - asyncio.create_task( - self.send(writer) - ) - ) - idd += 1 - await asyncio.gather(*(readers + writers)) - finally: - try: - await self.close_connections() - except RuntimeError: - pass - - -def main() -> None: - benchmark = Benchmark(n=DEFAULT_N) - try: - asyncio.run(benchmark.run()) - except KeyboardInterrupt: - pass