Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.9.18", "3.10.13", "3.12.1" ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov pytest-mock requests coverage pylint pycodestyle check-manifest readme_renderer
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: check-manifest
run: |
check-manifest
- name: confirm required package meta-data in setup.py
run: |
python setup.py check -m -s
- name: Analysing the code with pylint
run: |
pylint --max-line-length=127 $(git ls-files '*.py')
- name: Analysing the code with pycodestyle (formerly called pep8)
run: |
pycodestyle --max-line-length=127 --exclude=.svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/.coverage
/.eggs/
/.mypy_cache/
/.project
/.pydevproject
/.settings
/.tox/
/dist/
/build/
/dist/
/*.egg-info/
/__pycache__/
*.pyc
*.pyd
*.pyo
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/httpd-echo.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include tox.ini
include pytest.ini
include Makefile
include .idea/httpd-echo.iml
include .idea/inspectionProfiles/Project_Default.xml
include .idea/inspectionProfiles/profiles_settings.xml
include .idea/misc.xml
include .idea/modules.xml
include .idea/vcs.xml
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export PYTHONPATH=$(shell dirname "$(abspath $(lastword $(MAKEFILE_LIST)))")
name:=httpdecho


.PHONY: test
test:
python3 -m pytest -v


.PHONY: lint
lint:
python3 -m pylint *.py


.PHONY: build
build:
python3 -m build


.PHONY: clean
clean:
-python3 -m coverage erase
rm -rf site.py build/ dist/ .tox/ .pytest_cache/ .mypy_cache/
find . -depth \( -name '*.pyc' -o -name '__pycache__' -o -name '__pypackages__' \
-o -name '*.pyd' -o -name '*.pyo' -o -name '*.egg-info' \
-o -name '*.py,cover' \) -exec rm -rf \{\} \;
31 changes: 24 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
==========
httpd-echo
==========

A Simple Python HTTP server that echos the request in the response
------------------------------------------------------------------

Expand All @@ -21,16 +21,17 @@ starting at 8000 to try and be as predictable as possible::
>>> import sys
>>> import time
>>> import subprocess
>>> from six.moves import SimpleHTTPServer
>>> startup_delay = 0.5
>>> simple_popen = subprocess.Popen(
... [sys.executable, '-m', SimpleHTTPServer.__name__]
... [sys.executable, '-m', 'http.server']
... ); time.sleep(1)
>>> echo_popen = subprocess.Popen(
... [sys.executable, '-m', 'httpdecho']
... ); time.sleep(1)
>>> echo_popen.poll()
>>> simple_popen.kill()
>>> simple_popen.communicate()
(None, None)

Once running, HTTP requests are echoed in the responses. The default response
body format is basically HTTP header format, from
Expand Down Expand Up @@ -68,15 +69,31 @@ request, the body or the responses body will contain the POST body::
Shutdown the server::

>>> echo_popen.kill()
>>> echo_popen.communicate()
(None, None)


----------------------------
----
TODO
----------------------------
----


Features for future releases
____________________________

``Content-Type`` and ``Accept`` support for content negotiation:
- ``Content-Type`` and ``Accept`` support for content negotiation:

Return the response body in the format specified in the ``Accept`` header if
given, otherwise in the same ``Content-Type`` as the request.
given, otherwise in the same ``Content-Type`` as the request.

- ``HTTP 2/0`` and further support.

Tests
_____

- Use pytest and coverage to test every single line.

Pypi
----

- Upload, what else? ;-)
Loading