Skip to content

Commit c1d9e33

Browse files
authored
Support Flask 3.0 (#29)
1 parent ba1b151 commit c1d9e33

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

httpbin/core.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from werkzeug.wrappers import Response
3333
except ImportError: # werkzeug < 2.1
3434
from werkzeug.wrappers import BaseResponse as Response
35-
from werkzeug.http import parse_authorization_header
35+
3636
from flasgger import Swagger, NO_SANITIZER
3737

3838
from . import filters
@@ -47,6 +47,7 @@
4747
H,
4848
ROBOT_TXT,
4949
ANGRY_ASCII,
50+
parse_authorization_header,
5051
parse_multi_value_header,
5152
next_stale_after_value,
5253
digest_challenge_response,
@@ -636,16 +637,13 @@ def redirect_to():
636637
args_dict = request.args.items()
637638
args = CaseInsensitiveDict(args_dict)
638639

639-
# We need to build the response manually and convert to UTF-8 to prevent
640-
# werkzeug from "fixing" the URL. This endpoint should set the Location
641-
# header to the exact string supplied.
642640
response = app.make_response("")
643641
response.status_code = 302
644642
if "status_code" in args:
645643
status_code = int(args["status_code"])
646644
if status_code >= 300 and status_code < 400:
647645
response.status_code = status_code
648-
response.headers["Location"] = args["url"].encode("utf-8")
646+
response.headers["Location"] = args["url"]
649647

650648
return response
651649

httpbin/helpers.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
import time
1414
import os
1515
from hashlib import md5, sha256, sha512
16-
from werkzeug.http import parse_authorization_header
1716
from werkzeug.datastructures import WWWAuthenticate
17+
from werkzeug.http import dump_header
18+
19+
try:
20+
from werkzeug.http import parse_authorization_header
21+
except ImportError: # werkzeug < 2.3
22+
from werkzeug.datastructures import Authorization
23+
parse_authorization_header = Authorization.from_header
1824

1925
from flask import request, make_response
2026
from six.moves.urllib.parse import urlparse, urlunparse
@@ -466,9 +472,14 @@ def digest_challenge_response(app, qop, algorithm, stale = False):
466472
]), algorithm)
467473
opaque = H(os.urandom(10), algorithm)
468474

469-
auth = WWWAuthenticate("digest")
470-
auth.set_digest('[email protected]', nonce, opaque=opaque,
471-
qop=('auth', 'auth-int') if qop is None else (qop,), algorithm=algorithm)
472-
auth.stale = stale
475+
values = {
476+
'realm': '[email protected]',
477+
'nonce': nonce,
478+
'opaque': opaque,
479+
'qop': dump_header(('auth', 'auth-int') if qop is None else (qop,)),
480+
'algorithm': algorithm,
481+
'stale': stale,
482+
}
483+
auth = WWWAuthenticate("digest", values=values)
473484
response.headers['WWW-Authenticate'] = auth.to_header()
474485
return response

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,13 @@ classifiers = [
3131
"Programming Language :: Python :: 3.12",
3232
]
3333
dependencies = [
34-
"Flask",
34+
"flask >= 2.2.4",
3535
"brotlicffi",
3636
"decorator",
3737
"flasgger",
3838
'greenlet < 3.0; python_version<"3.12"',
3939
'greenlet >= 3.0.0a1; python_version>="3.12.0rc0"',
4040
'importlib-metadata; python_version<"3.8"',
41-
"werkzeug >= 0.14.1",
4241
"six",
4342
]
4443

0 commit comments

Comments
 (0)