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

Fix use of HTTPS proxies #1070 #1077

Merged
merged 4 commits into from
Mar 4, 2024
Merged

Conversation

jakob-keller
Copy link
Collaborator

@jakob-keller jakob-keller commented Jan 20, 2024

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

  • I have added change info to CHANGES.rst
  • If this is resolving an issue (needed so future developers can determine if change is still necessary and under what conditions) (can be provided via link to issue with these details): closes Proxy not working due to signature mismatch #1070
    • Detailed description of issue
    • Alternative methods considered (if any)
    • How issue is being resolved: Use separate aiohttp sessions per proxy URL and merge any relevant configuration options into a single ssl.SSLContext to be used both for connections to the HTTPS proxy as well as the HTTPS endpoint
    • How issue can be reproduced
  • If this is providing a new feature (can be provided via link to issue with these details):
    • Detailed description of new feature
    • Why needed
    • Alternatives methods considered (if any)

Checklist when updating botocore and/or aiohttp versions

  • I have read and followed CONTRIBUTING.rst
  • I have updated test_patches.py where/if appropriate (also check if no changes necessary)
  • I have ensured that the awscli/boto3 versions match the updated botocore version

Copy link

codecov bot commented Jan 20, 2024

Codecov Report

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

Project coverage is 86.29%. Comparing base (c74c796) to head (704508c).
Report is 76 commits behind head on master.

Files Patch % Lines
aiobotocore/httpsession.py 96.87% 1 Missing ⚠️
Additional details and impacted files
@@            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 Coverage Δ
unittests 86.29% <96.96%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jakob-keller jakob-keller marked this pull request as ready for review January 20, 2024 00:06
@jakob-keller jakob-keller added the bug Something isn't working label Jan 20, 2024
@thehesiod
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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

@thehesiod
Copy link
Collaborator

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

@jakob-keller
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@thehesiod
Copy link
Collaborator

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

request.method,
url=url,
chunked=chunked,
chunked=self._chunked(headers_),
Copy link
Collaborator Author

@jakob-keller jakob-keller Mar 3, 2024

Choose a reason for hiding this comment

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

I'm not sure we need to deal with chunked at all. To me it seems that aiohttp is able to handle that internally at least since aio-libs/aiohttp@2c85834.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm, seems like there's test coverage so it seems like you could pull it out to see what happens (assuming it's an integration test to ensure it's testing w/ aiohttp and moto)

Copy link
Collaborator

Choose a reason for hiding this comment

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

although I'd open an issue with comments for better testing in this area as well to do later unless you feel very motivated :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's see what happens: #1096

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

although I'd open an issue with comments for better testing in this area as well to do later unless you feel very motivated :)

Unit tests in what's still an unfamiliar codebase are not my strong suit :-/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's see what happens: #1096

CI doesn't complain, but I'm not sure that's enough evidence. Maybe aiohttp folks can weigh in?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can just add a test later, i think werkzerg via moto should be able to handle it

@jakob-keller
Copy link
Collaborator Author

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

@thehesiod
Copy link
Collaborator

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
Copy link
Collaborator

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

@jakob-keller
Copy link
Collaborator Author

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
Copy link
Collaborator

thank you so much, sorry for delay!

@thehesiod thehesiod merged commit e8a3b8e into aio-libs:master Mar 4, 2024
12 checks passed
@jakob-keller jakob-keller deleted the proxy branch March 4, 2024 19:15
@jakob-keller
Copy link
Collaborator Author

Thanks for the thorough review! Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proxy not working due to signature mismatch
2 participants