Skip to content

Use Pipe instead of Queue when passing sockets #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Sep 17, 2019
33 changes: 33 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Proxy.py

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python: [3.6, 3.7]
max-parallel: 4
fail-fast: false
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}
architecture: x64
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-testing.txt
- name: Lint Checker
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 proxy.py tests.py --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 proxy.py tests.py --count --exit-zero --max-line-length=127 --statistics
- name: Run Tests
run: |
pytest tests.py
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ EXPOSE 8899/tcp

WORKDIR /app
ENTRYPOINT [ "./proxy.py" ]
CMD [ "--host=0.0.0.0", \
"--port=8899" ]
CMD [ "--port=8899" ]
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VERSION ?= v$(shell python proxy.py --version)
LATEST_TAG := $(NS)/$(IMAGE_NAME):latest
IMAGE_TAG := $(NS)/$(IMAGE_NAME):$(VERSION)

.PHONY: all clean test package test-release release coverage flake8 container run-container release-container
.PHONY: all clean test package test-release release coverage lint container run-container release-container

all: clean test

Expand Down Expand Up @@ -35,9 +35,11 @@ coverage:
coverage3 html
open htmlcov/index.html

flake8:
lint:
flake8 --ignore=E501,W504 --builtins="unicode" proxy.py
flake8 --ignore=E501,W504 tests.py
autopep8 --recursive --in-place --aggressive --aggressive proxy.py
autopep8 --recursive --in-place --aggressive --aggressive tests.py

container:
docker build -t $(LATEST_TAG) -t $(IMAGE_TAG) .
Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
[![Proxy.Py](ProxyPy.png)](https://github.com/abhinavsingh/proxy.py)

[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![alt text](https://travis-ci.org/abhinavsingh/proxy.py.svg?branch=develop "Build Status")](https://travis-ci.org/abhinavsingh/proxy.py/) [![Coverage Status](https://coveralls.io/repos/github/abhinavsingh/proxy.py/badge.svg?branch=develop)](https://coveralls.io/github/abhinavsingh/proxy.py?branch=develop)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![PyPi Downloads](https://img.shields.io/pypi/dm/proxy.py.svg)](https://pypi.org/project/proxy.py/)
[![Build Status](https://travis-ci.org/abhinavsingh/proxy.py.svg?branch=develop)](https://travis-ci.org/abhinavsingh/proxy.py/)
[![Coverage](https://coveralls.io/repos/github/abhinavsingh/proxy.py/badge.svg?branch=develop)](https://coveralls.io/github/abhinavsingh/proxy.py?branch=develop)

[![Twitter](https://img.shields.io/twitter/follow/imoracle?label=Follow%20on%20Twitter&style=social)](https://twitter.com/imoracle)

Features
--------

- Distributed as a single file module
- Optionally enable builtin Web Server
- Customize proxy and http routing via plugins
- No external dependency other than standard Python library
- Support for `http`, `https`, `http2` and `websockets` request proxy
- Optimized for large file uploads and downloads
- IPv4 and IPv6 support
- Basic authentication support
- Can serve a [PAC (Proxy Auto-configuration)](https://en.wikipedia.org/wiki/Proxy_auto-config) file
- Optionally enable builtin Web Server
- Customize proxy and http routing via [plugins](https://github.com/abhinavsingh/proxy.py/blob/develop/plugin_examples.py)

Install
-------

To install proxy.py, simply:
#### Stable version

$ pip install --upgrade proxy.py

Using docker:
#### Development version

$ pip install git+https://github.com/abhinavsingh/proxy.py.git@develop

#### Docker image

$ docker run -it -p 8899:8899 --rm abhinavsingh/proxy.py

Expand Down
20 changes: 19 additions & 1 deletion plugin_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def before_upstream_connection(self):
# Redirect all non-https requests to inbuilt WebServer.
self.request.url = urlparse.urlsplit(b'http://localhost:8899')

def on_upstream_connection(self):
pass

def handle_upstream_response(self, raw):
return raw


class FilterByTargetDomainPlugin(proxy.HttpProxyBasePlugin):
"""Only accepts specific requests dropping all other requests."""
Expand All @@ -26,7 +32,13 @@ def before_upstream_connection(self):
# are not consistent between CONNECT and non-CONNECT requests.
if (self.request.method != b'CONNECT' and self.filtered_domain in self.request.url.hostname) or \
(self.request.method == b'CONNECT' and self.filtered_domain in self.request.url.path):
raise proxy.HttpRequestRejected(status_code=418, body='I\'m a tea pot')
raise proxy.HttpRequestRejected(status_code=418, body=b'I\'m a tea pot')

def on_upstream_connection(self):
pass

def handle_upstream_response(self, raw):
return raw


class SaveHttpResponses(proxy.HttpProxyBasePlugin):
Expand All @@ -37,3 +49,9 @@ def __init__(self, config, client, request):

def handle_upstream_response(self, chunk):
return chunk

def before_upstream_connection(self):
pass

def on_upstream_connection(self):
pass
Loading