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
add httpx support #523
add httpx support #523
Conversation
hey @herdigiorgi ! Thanks for the PR. 👍 Maybe I'm doing something wrong, so bellow is a dummy example of what I'm trying to test and save into a cassette. I have included a sync and async version, because the sync version works.
After installing your branch version, I was able to save the cassette, but when running again the same test I got the follow error:
The libraries version:
Also I try to ran the above code example using Any suggestion or workaround? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, it's really interesting, but some scenarios should be reviewed, like the issue exposed by @fullonic.
Many thanks @herdigiorgi 🍻
vcr/stubs/httpx_stubs.py
Outdated
|
||
while 300 <= response.status_code <= 399: | ||
location = response.headers["location"] | ||
next_url = URL(str(response.url)).with_path(location) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the example provided by @fullonic this breaks the composition of the next_url
.
Result of the issued scenario described by @fullonic:
response.url
:URL('https://github.com/kevin1024/vcrpy/issues/1')
response.headers.get('location')
:https://github.com/kevin1024/vcrpy/pull/1
location
:URL('https://github.com/https://github.com/kevin1024/vcrpy/pull/1')
It's really needed? Why we couldn't just use the location reached from the response headers and validate if it's an absolute or relative?
Maybe something like this can help:
next_url = URL(response.headers["location"])
if not next_url.is_absolute():
# could be simplified, it's just a quick example :)
next_url = URL(str(response.url)).with_path(next_url)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! (: I fixed this, and also I stop the loop if there is no location
as suggested in #511.
Today while using this I noticed other problems 😅, so that's why you will find more commits. |
mmm... I will fix CI tomorrow. |
Thanks @XaviTorello and @herdigiorgi . I ran again the sample code with our new changes and it works! Maybe we could apply the same changes to the aiohttp stubs to fixed as well? |
Codecov Report
@@ Coverage Diff @@
## master #523 +/- ##
==========================================
- Coverage 89.41% 84.86% -4.55%
==========================================
Files 24 25 +1
Lines 1549 1619 +70
Branches 216 221 +5
==========================================
- Hits 1385 1374 -11
- Misses 135 215 +80
- Partials 29 30 +1
Continue to review full report at Codecov.
|
Now CI passes 🎉 |
There is already a PR that only needs to be merged: https://github.com/kevin1024/vcrpy/pull/511/files. I think it wasn't merged because there isn't an active |
I started using this branch in one project and noticed that cookies were not extracted to the client session cookie jar anymore when requests/responses were replayed from cassettes. Added tests for that situation and fixed it in PRs to this PR branch: Also enabled running Travis CI for httpx. That also revealed that httpx is not available for Python 3.5. Can we disable that when testing vcrpy with httpx? |
@herdigiorgi @XaviTorello what needs to be done on this pull request to be merged? |
@jairhenrique I'm currently using this branch 😄, so from from my side I think it is done. |
@kevin1024 can you help here? |
@IvanMalison can you help this to go to master? |
@herdigiorgi can you add |
@jairhenrique |
This looks awesome. Any way to get Travis to pass before I merge? |
Could I get a rebase on this? If tests pass I'll merge. |
This is required because previous extraction code is now patched out by vcpy. Also handle headers with same key in responses.
Because the recoded requests are using original value. Changing the value on redirect prevents finding the matching response.
@herdigiorgi httpx doesn't support python 3.5. |
fyi, I will take care of the errors in the next 2 days. |
Ignore utf8 decoding errors in content
- Use mockbin for redirections. - Mock synchronous requests too.
Codecov Report
@@ Coverage Diff @@
## master #523 +/- ##
==========================================
- Coverage 89.01% 84.03% -4.99%
==========================================
Files 24 26 +2
Lines 1539 1704 +165
Branches 212 239 +27
==========================================
+ Hits 1370 1432 +62
- Misses 139 237 +98
- Partials 30 35 +5
Continue to review full report at Codecov.
|
Tests pass now. (: |
🚀 @kevin1024 can you bump a new version with this? |
OK, it's released! Thanks so much for your contributions. |
This PR adds support for httpx.
The stub and tests are heavily based in the
aiohttp
implementation. You won't see any synchronous implementation because it was not necessary.Not sure if I edited the
tox
file correctly. (: