Use Response instead of BaseResponse#674
Use Response instead of BaseResponse#674maximino-dev wants to merge 1 commit intopostmanlabs:masterfrom
Conversation
|
You may want to add With your patch, httpbin would have a strong dependency on werkzeug. I don't know what's httpbin policy on dependencies, but I guess you need to either:
|
|
Agreed, we might want to use something like this: try:
from werkzeug.wrappers import Response
except ImportError: # werkzeug < 2.1
from werkzeug.wrappers import BaseResponse as Response |
|
The Response class is written even in the old werzeug versions, but in the version 1.x and older, there's not the |
|
I agree with @maximino-dev that updating the pipfiles to a >=2.0 constraint on werkzeug and exclusively using try:
from werkzeug.wrappers import BaseResponse as Response
except ImportError: # werkzeug >= 2.1
from werkzeug.wrappers import ResponseThis will use |
|
FYI, Werkzeug 2.0 was released on May 11th, 2021 (i.e. not "very recent" but not so old either), so it may be nice to support older versions if there's a simple way to do it. No strong opinion here, and I leave it to the httpbin maintainers anyway to decide. |
As per #649, for werkzeug >= 2.0 (note that the boundary is not 2.1), |
|
So we can maybe try something like this : try:
from werkzeug.wrappers import Response
from werkzeug.wrappers import BaseResponse
except ImportError: # werkzeug >= 2.1.0
from werkzeug.wrappers import Response
. . .
try:
Response.autocorrect_location_header = False
except NameError: # werkzeug < 2.0.0
BaseResponse.autocorrect_location_header = FalseIt imports Response and BaseResponse for werkzeug < 2.1.0 (otherwise just Response for werkzeug >= 2.1.0) and changes the |
|
I think @maximino-dev's solution covers all the bases. However, it seems a shame to encode the complicated history of werkzeug into this library. Perhaps we could just add a werkzeug 2.0+ requirement to this PR and call it a day? |
Definitely fine for me! Anyway, that's up to postmanlabs developers. Maybe @MikeRalphson (reviewer of #649) can give some suggestions? Sorry for bothering if you no longer work on this. |
Keeping compatibility with older werkzeug can be quite complicated, so I decided to only consider the latest werkzeug and use the simplest patch. The patch httpbin-werkzeug-2.0.0.patch is no longer needed, as it fixes the same issue as httpbin-werkzeug-2.1.0.patch: `autocorrect_location_header` not set on the correct class. Fixes https://bugs.archlinux.org/task/74443 See: postmanlabs/httpbin#674 git-svn-id: file:///srv/repos/svn-community/svn@1186428 9fca08f4-af9d-4005-b8df-a31f2cc04f65
Keeping compatibility with older werkzeug can be quite complicated, so I decided to only consider the latest werkzeug and use the simplest patch. The patch httpbin-werkzeug-2.0.0.patch is no longer needed, as it fixes the same issue as httpbin-werkzeug-2.1.0.patch: `autocorrect_location_header` not set on the correct class. Fixes https://bugs.archlinux.org/task/74443 See: postmanlabs/httpbin#674 git-svn-id: file:///srv/repos/svn-community/svn@1186428 9fca08f4-af9d-4005-b8df-a31f2cc04f65
|
Hey, FWIW this is the open issue on FreeBSD's ports tree: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263650 |
|
All of these versions of the patch ignore something rather important -
and then later does stuff like In my version downstream ATM I do this:
|
|
Yes, the import will need to be aliased. @maximino-dev would you be willing to update your PR to address this point? Thanks! |
5cc81ce to
651c03a
Compare
|
You're right, I updated it ! |
|
The PR looks good to me, and takes all comments into account. I'm not familiar enough with the codebase to claim an official "approve" in a review, but I believe the PR can be merged. It's rather important since the tool is actually broken without this PR with the latest werkzeug. |
To fix the issue mentioned at postmanlabs/httpbin#674 (comment) git-svn-id: file:///srv/repos/svn-community/svn@1349198 9fca08f4-af9d-4005-b8df-a31f2cc04f65
To fix the issue mentioned at postmanlabs/httpbin#674 (comment) git-svn-id: file:///srv/repos/svn-community/svn@1349198 9fca08f4-af9d-4005-b8df-a31f2cc04f65
In the new werkzeug version released on 2022 - 03 - 28, the BaseResponse class has been removed (because it's deprecated) and replaced by Response. Using the Response class in the core.py file will now probably resolve incompatibility issues.
Fixes #673