-
Notifications
You must be signed in to change notification settings - Fork 404
Wrap the Rust HTTP client with make_deferred_yieldable
#18903
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
Merged
MadLittleMods
merged 28 commits into
develop
from
madlittlemods/18357-rust-http-client-remove-preserve-logging-context
Oct 2, 2025
+272
−18
Merged
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
986e15c
Wrap the Rust HTTP client with `make_deferred_yieldable`
MadLittleMods 5e555f3
Add chagnelog
MadLittleMods 4e0085c
Docstring for why we have a wrapper
MadLittleMods 763cdb9
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods ce6f16d
WIP: Add test
MadLittleMods d4558df
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods dce9754
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods 9def6f7
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods 77970eb
Maintenance from merging in the latest `develop` changes
MadLittleMods b89fb2e
Fix `Tokio runtime is not running`
MadLittleMods 34b6f2a
Add working test
MadLittleMods 8a9d682
Add basic request/response test
MadLittleMods 2d341cb
Add docstring
MadLittleMods 58c1209
Better test that fails
MadLittleMods 9a4e67d
Cross-link Twisted PR
MadLittleMods 59516a4
WIP: Failing test
MadLittleMods 74f01a9
Use `make_deferred_yieldable` in Rust
MadLittleMods 4424a88
Clean up test
MadLittleMods e6df6ee
Remove Rust wrapper (no longer necessary)
MadLittleMods 92ea10a
Note that the returned deferred follow Synapse logcontext rules now
MadLittleMods 5c324bc
No more Rust wrapper (switch back to Rust imports)
MadLittleMods e243b0f
Fix lints
MadLittleMods ab453b7
Move imports (try fix lints)
MadLittleMods a0051f7
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods e35c7db
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods 1d9ae7f
Avoid `unwrap` and return fallible
MadLittleMods 311969f
Always `make_deferred_yieldable(...)` when `create_deferred(...)`
MadLittleMods b670864
Merge branch 'develop' into madlittlemods/18357-rust-http-client-remo…
MadLittleMods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Wrap the Rust HTTP client with `make_deferred_yieldable` so it follows Synapse logcontext rules. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| # | ||
| # Copyright (C) 2025 New Vector, Ltd | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License as | ||
| # published by the Free Software Foundation, either version 3 of the | ||
| # License, or (at your option) any later version. | ||
| # | ||
| # See the GNU Affero General Public License for more details: | ||
| # <https://www.gnu.org/licenses/agpl-3.0.html>. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # This file is licensed under the Affero General Public License (AGPL) version 3. | ||
| # | ||
| # Copyright (C) 2025 New Vector, Ltd | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU Affero General Public License as | ||
| # published by the Free Software Foundation, either version 3 of the | ||
| # License, or (at your option) any later version. | ||
| # | ||
| # See the GNU Affero General Public License for more details: | ||
| # <https://www.gnu.org/licenses/agpl-3.0.html>. | ||
|
|
||
|
|
||
| from typing import Mapping | ||
|
|
||
| from twisted.internet.defer import Deferred | ||
|
|
||
| from synapse.logging.context import make_deferred_yieldable | ||
| from synapse.synapse_rust.http_client import HttpClient as RustHttpClient | ||
| from synapse.types import ISynapseReactor | ||
|
|
||
|
|
||
| class HttpClient: | ||
| """ | ||
| Wrap `synapse.synapse_rust.http_client.HttpClient` to ensure the returned | ||
| deferreds follow Synapse logcontext rules. | ||
| """ | ||
|
|
||
| def __init__(self, reactor: ISynapseReactor, user_agent: str) -> None: | ||
| self._http_client = RustHttpClient(reactor, user_agent) | ||
|
|
||
| def get(self, url: str, response_limit: int) -> Deferred[bytes]: | ||
| deferred = self._http_client.get(url, response_limit) | ||
| return make_deferred_yieldable(deferred) | ||
|
|
||
| def post( | ||
| self, | ||
| url: str, | ||
| response_limit: int, | ||
| headers: Mapping[str, str], | ||
| request_body: str, | ||
| ) -> Deferred[bytes]: | ||
| deferred = self._http_client.post(url, response_limit, headers, request_body) | ||
| return make_deferred_yieldable(deferred) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.