Skip to content
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

Support Flask 3.0 #29

Merged
merged 2 commits into from
Oct 12, 2023
Merged

Support Flask 3.0 #29

merged 2 commits into from
Oct 12, 2023

Conversation

nateprewitt
Copy link
Member

@nateprewitt nateprewitt commented Oct 6, 2023

This PR should get httpbin working with Flask 3.0. The other recent changes to get Flask 2.0 working in main already broke Flask<2.2.4 so I've updated the dependencies to correctly reflect what we're compatible with. This should also resolve #28.

This PR changes three primary pieces:

  1. Move to using the WWWAuthenticate constructor that was introduced in werkzeug 2.0 and became the only supported interface in werkzeug 3.0.
  2. Move to Authorization.from_header which was introduced in werkzeug 2.3 and is the only supported interface in werkzeug 3.0. parse_authorization_header was already an alias for this in versions of werkzeug we support.
  3. We were doing some unneeded byte conversion for the Location header on redirect. This was a legacy change from 10 years ago to accommodate werkzeug casting all headers to str so we ensured they were utf-8 bytes. werkzeug stopped this conversion in 3.0 and we already have a Python 3 utf-8 string as input. We should be able drop this safely with our support range.

Copy link

@jeffvanvoorst jeffvanvoorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good fix. I wasn't aware of the details for .helpers.

response = app.make_response("")
response.status_code = 302
if "status_code" in args:
status_code = int(args["status_code"])
if status_code >= 300 and status_code < 400:
response.status_code = status_code
response.headers["Location"] = args["url"].encode("utf-8")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this issue resolved in a later version of werkzeug? I am curious to understand why it is no longer necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's covered in item 3 in the PR overview. Was there something more specific you were wondering about?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, thanks for pointing that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fails to import with werkzeug 3.0
3 participants