aio-libs / aiobotocore

asyncio support for botocore library using aiohttp
https://aiobotocore.rtfd.io
Apache License 2.0
1.14k stars 179 forks source link

Fix use of HTTPS proxies #1070 #1077

Closed jakob-keller closed 5 months ago

jakob-keller commented 7 months ago

Description of Change

This PR fixes support for HTTPS proxies.

Assumptions

Connection to the HTTPS proxy and to the HTTPS endpoint may use a single ssl.SSLContext.

Checklist for All Submissions

Checklist when updating botocore and/or aiohttp versions

codecov[bot] commented 7 months ago

Codecov Report

Attention: Patch coverage is 96.96970% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 86.29%. Comparing base (c74c796) to head (704508c).

Files Patch % Lines
aiobotocore/httpsession.py 96.87% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1077 +/- ## ========================================== + Coverage 86.23% 86.29% +0.06% ========================================== Files 62 62 Lines 5885 5889 +4 ========================================== + Hits 5075 5082 +7 + Misses 810 807 -3 ``` | [Flag](https://app.codecov.io/gh/aio-libs/aiobotocore/pull/1077/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aio-libs) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/aio-libs/aiobotocore/pull/1077/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aio-libs) | `86.29% <96.96%> (+0.06%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aio-libs#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

thehesiod commented 5 months ago

sorry for delay! Kids got hand foot mouth sequentially and I've been working on getting our condo back on the market due to tenant destruction (pain) with no money (they didn't pay). Will get to this ASAP.

jakob-keller commented 5 months ago

sorry for delay! Kids got hand foot mouth sequentially and I've been working on getting our condo back on the market due to tenant destruction (pain) with no money (they didn't pay). Will get to this ASAP.

Ouch, I feel ya! Take your time!

thehesiod commented 5 months ago

gonna get this done today! (pep talking myself lol)

thehesiod commented 5 months ago

is it possible to use their proxy manager concept to make the logic more similar? would help to maintain going forwards.

jakob-keller commented 5 months ago

is it possible to use their proxy manager concept to make the logic more similar? would help to maintain going forwards.

I don't see how. We don't use (proxy) managers at all.

We could create a ._get_session() method that extracts relevant logic from .send(), if that is what you propose. Should I give it a try?

jakob-keller commented 5 months ago

I just rebased the PR onto main and added a commit that pulls out session creation into ._get_session(). It makes the code a bit more readable, but introduces another round trip through the event loop, which could have a minor performance impact. Let me know, what you think. I can drop the commit easily.

thehesiod commented 5 months ago

ok looks great, we really need to add a proxy test later though. One suggestion, replace:

            chunked = None
            if headers_.get('Transfer-Encoding', '').lower() == 'chunked':
                # aiohttp wants chunking as a param, and not a header
                headers_.pop('Transfer-Encoding', '')
                chunked = True

with something like this function after _get_session

    def _chunked(self, headers):
        transfer_encoding = headers.get('Transfer-Encoding', '')
        if chunked := transfer_encoding.lower() == 'chunked':
            # aiohttp wants chunking as a param, and not a header
            headers.pop('Transfer-Encoding', '')
        return chunked

so it matches botocore some more.

thehesiod commented 5 months ago

oh and then chunked=self._chunked(headers_),

thehesiod commented 5 months ago

thank you and sorry for the delays! finally finished the painting, now for all the other 1000 tiny things to fix lol

jakob-keller commented 5 months ago

I have no idea, why CI is failing. This should be unrelated to this PR.

thehesiod commented 5 months ago

hmm:

>               raise ParamValidationError(report=report.generate_report())
E               botocore.exceptions.ParamValidationError: Parameter validation failed:
E               Invalid type for parameter TopicArn, value: None, type: <class 'NoneType'>, valid types: <class 'str'>

https://github.com/aio-libs/aiobotocore/actions/runs/8129847790/job/22217412080?pr=1077

thehesiod commented 5 months ago

hmm, also seeing an xml parse error, I wonder if it's moto that got upgraded

jakob-keller commented 5 months ago

I have no idea, why CI is failing. This should be unrelated to this PR.

For some reason chunked=None is not equivalent to chunked=False. I just reverted to the old logic and now CI is passing.

thehesiod commented 5 months ago

thank you so much, sorry for delay!

jakob-keller commented 5 months ago

Thanks for the thorough review! Much appreciated!