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

refactor: HTTPClient Re-Core #1057

Merged
merged 103 commits into from
May 17, 2024
Merged

Conversation

alentoghostflame
Copy link
Collaborator

@alentoghostflame alentoghostflame commented May 13, 2023

Summary

Massively reworks the core of HTTP, adding support for:

  • Multiple authorization tokens/types with the auth kwarg, opening the way for OAuth2 extensions,
  • Global ratelimits per authorization, to stay within the (default) 50 requests per second per auth maximum,
  • Proper rate limit bucket handling, allowing multiple requests in a single bucket to run simultaneously, unlike the previous implementation,
  • The retry_request kwarg, allowing the user to disable auto-retries on ratelimit or Discord server errors.

Due to restructuring, there HAS been some breaking changes.

  • Documentation and comments will likely need to be updated across the board.
  • MaybeUnlock has been removed and replaced with a completely different RateLimit.
  • HTTPClient.request() will no longer overwrite specific provided headers, allowing you, for example, to override the auth and user-agent.
  • Due to HTTPClient no longer being centered around a single token, the HTTPClient.token attribute has been removed and Client._token has been added.
    • This can be added back of course, but hmm.
  • While HTTPClient may technically not be documented, almost all of its attributes were not _'d, and thus were technically public. Since basically all of those attributes are gone/renamed, definitely a breaking change there,
  • HTTPClient.static_login() was modified to better fit with the rework of HTTPClient.

Notes:

  • Webhook and HTTPClient had their own rate limiting implementations before this PR, and with this PR still do. To avoid more delays, migrating webhooks to use HTTPClient is not in this PR.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have run task pyright and fixed the relevant issues.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

alentoghostflame and others added 5 commits May 12, 2023 22:18
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
… raising errors instead.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
@MaskDuck
Copy link
Contributor

MaskDuck commented May 13, 2023

I demand a rename of the title

@alentoghostflame
Copy link
Collaborator Author

oh shoot I knew I forgot something

@alentoghostflame alentoghostflame changed the title Initial Commit HTTPClient Re-Core May 13, 2023
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
alentoghostflame and others added 2 commits May 15, 2023 23:03
…ting, adds RateLimits erroring if a bucket update unintended for them is given, now resets the bucket reset timer when pessimistic RateLimit.reset_after is updated, fixes edge cases where the RateLimit reset timer is never started, adds and changes logging messages, *_url_rate_limit() and *_url_deny() methods now take Route instead of path, improved behavior of bucket changes when using asyncio.gather().

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
alentoghostflame and others added 2 commits May 17, 2023 20:30
…eLimit docstring, cleans up (Global)RateLimit checking if the global ratelimit was hit.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
@Skelmis
Copy link
Collaborator

Skelmis commented May 24, 2023

Regardless I also think that kind of information is too high level / frequent for info

alentoghostflame and others added 5 commits May 24, 2023 08:09
…ct most of token in logging when possible.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
… of token when possible.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
…mit time offsets, readds dispatching http_ratelimit.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
@EmreTech EmreTech added s: in progress Status: the issue or PR is in development/progress p: low Priority: low - not important to be worked on t: refactor Type: refactor - this is a code change but does not fix a bug/add features labels Jun 2, 2023
nextcord/http.py Fixed Show fixed Hide fixed
nextcord/http.py Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
alentoghostflame and others added 6 commits April 1, 2024 19:38
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex <alex@darkkingdom.lan>
… to a private function

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
@teaishealthy teaishealthy self-requested a review May 11, 2024 22:12
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Copy link
Collaborator

@EmreTech EmreTech left a comment

Choose a reason for hiding this comment

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

Few more suggestions left, sorry 😭
It's all documentation stuff at this point tho

docs/api.rst Show resolved Hide resolved
nextcord/http.py Outdated Show resolved Hide resolved
nextcord/http.py Show resolved Hide resolved
alentoghostflame and others added 11 commits May 13, 2024 18:33
Co-authored-by: Emre Terzioglu <50607143+EmreTech@users.noreply.github.com>
… docstring to a comment above, add real docstring

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
@ooliver1 ooliver1 dismissed stale reviews from EmreTech, Skelmis, and teaishealthy May 17, 2024 22:04

outdated

Copy link
Member

@ooliver1 ooliver1 left a comment

Choose a reason for hiding this comment

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

Tested by others is good 👍, merging since 3.0 is in development anyway and this is a large change.

@ooliver1 ooliver1 merged commit cf81368 into nextcord:master May 17, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 The issue/PR should go for the 3.0 release p: low Priority: low - not important to be worked on s: in progress Status: the issue or PR is in development/progress t: refactor Type: refactor - this is a code change but does not fix a bug/add features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants