Skip to content

Commit 6d9ad4e

Browse files
Merge pull request #44 from mdsol/fix/body-bug
2 parents cc956ff + 06c5359 commit 6d9ad4e

File tree

8 files changed

+299
-273
lines changed

8 files changed

+299
-273
lines changed

.github/workflows/check.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
strategy:
2828
matrix:
2929
os: [Ubuntu, macOS, Windows]
30-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
30+
python-version: ["3.8", "3.9", "3.10", "3.11"]
3131
include:
3232
- os: Ubuntu
3333
image: ubuntu-latest

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.6.0
2+
- Fix bug with reading request body in `MAuthWSGIMiddleware`.
3+
- Remove Support for EOL Python 3.7
4+
15
# 1.5.1
26
- Fix `MAuthWSGIMiddleware` to no longer depend on `werkzeug` data in the request env.
37

docs/faq.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ The framework is licensed under the MIT licensing terms.
88
What versions of Python are supported?
99
--------------------------------------
1010
Each release of requests-mauth is tested against:
11-
* Python 3.5
12-
* Python 3.6
13-
* Python 3.7
11+
* Python 3.8
12+
* Python 3.9
13+
* Python 3.10
14+
* Python 3.11
1415
* PyPy3
1516

1617
The values tested can be seen in the `tox.ini` file. We use tox to test the code across Python versions, see the README.md for details.

mauth_client/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
# Load the version from the project metatdata
2-
try:
3-
import importlib.metadata as importlib_metadata
4-
except ModuleNotFoundError:
5-
# needed for Python < 3.8
6-
import importlib_metadata
2+
import importlib.metadata as importlib_metadata
73

84
__version__ = importlib_metadata.version(__name__)

mauth_client/middlewares/wsgi.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import json
23
import logging
34

@@ -57,10 +58,29 @@ def _validate_configs(self):
5758
raise TypeError("MAuthWSGIMiddleware requires MAUTH_URL and MAUTH_API_VERSION")
5859

5960
def _read_body(self, environ):
60-
input = environ["wsgi.input"]
61-
input.seek(0)
62-
body = input.read()
63-
input.seek(0)
61+
try:
62+
size = int(environ.get("CONTENT_LENGTH", 0))
63+
except ValueError:
64+
size = 0
65+
66+
if not size:
67+
return b""
68+
69+
body = environ["wsgi.input"].read(size)
70+
71+
# hack way of "rewinding" body so that downstream can reuse
72+
#
73+
# seek() will not work because production Flask and gunicorn give
74+
# objects without a seek() function and blow up...
75+
# yet humorously Flask in our tests gives a normal BytesIO object
76+
# that does have seek()
77+
#
78+
# NOTE:
79+
# this will not play well with large bodies where this may result in
80+
# blowing out memory, but tbh MAuth is not adequately designed for and
81+
# thus should not be used with large bodies.
82+
environ["wsgi.input"] = io.BytesIO(body)
83+
6484
return body
6585

6686
def _extract_headers(self, environ):

poetry.lock

+261-254
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "mauth-client"
3-
version = "1.5.1"
3+
version = "1.6.0"
44
description = "MAuth Client for Python"
55
repository = "https://github.com/mdsol/mauth-client-python"
66
authors = ["Medidata Solutions <[email protected]>"]
@@ -13,7 +13,6 @@ classifiers = [
1313
"License :: OSI Approved :: MIT License",
1414
"Operating System :: OS Independent",
1515
"Programming Language :: Python",
16-
"Programming Language :: Python :: 3.7",
1716
"Programming Language :: Python :: 3.8",
1817
"Programming Language :: Python :: 3.9",
1918
"Programming Language :: Python :: 3.10",
@@ -23,11 +22,10 @@ classifiers = [
2322
]
2423

2524
[tool.poetry.dependencies]
26-
python = "^3.7"
25+
python = "^3.8"
2726
requests = "^2.23"
2827
cachetools = "^5.3"
2928
rsa = "^4.0"
30-
importlib-metadata = {version = ">=3.6", python = "<3.8"}
3129
asgiref = "^3.5.2"
3230
charset-normalizer = "^3.1.0"
3331

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = clean, flake8-py3, py37, py38, py39, py310, py311, stats
2+
envlist = clean, flake8-py3, py38, py39, py310, py311, stats
33
skipsdist = True
44

55
[testenv]
@@ -15,7 +15,7 @@ skip_install = true
1515
commands = coverage erase
1616

1717
[testenv:flake8-py3]
18-
basepython = python3.10
18+
basepython = python3.11
1919
allowlist_externals = poetry
2020
skip_install = true
2121
commands =

0 commit comments

Comments
 (0)