This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into flag-boilerplate
- Loading branch information
Showing
9 changed files
with
276 additions
and
67 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,9 +17,7 @@ jobs: | |
- uses: actions/checkout@v3 | ||
|
||
- name: Install rust | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: stable | ||
uses: dtolnay/[email protected] | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
|
@@ -52,9 +50,7 @@ jobs: | |
echo "127.0.0.1 kafka" | sudo tee -a /etc/hosts | ||
- name: Install rust | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: stable | ||
uses: dtolnay/[email protected] | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
|
@@ -73,10 +69,9 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install latest rust | ||
uses: dtolnay/rust-toolchain@master | ||
- name: Install rust | ||
uses: dtolnay/rust-toolchain@1.77 | ||
with: | ||
toolchain: stable | ||
components: clippy,rustfmt | ||
|
||
- uses: actions/cache@v3 | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
Empty file.
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod config; | ||
pub mod error; | ||
pub mod util; | ||
pub mod worker; |
This file contains 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,35 @@ | ||
use crate::error::WebhookResponseError; | ||
use futures::StreamExt; | ||
use reqwest::Response; | ||
|
||
pub async fn first_n_bytes_of_response( | ||
response: Response, | ||
n: usize, | ||
) -> Result<String, WebhookResponseError> { | ||
let mut body = response.bytes_stream(); | ||
let mut buffer = String::with_capacity(n); | ||
|
||
while let Some(chunk) = body.next().await { | ||
if buffer.len() >= n { | ||
break; | ||
} | ||
|
||
let chunk = chunk?; | ||
let chunk_str = std::str::from_utf8(&chunk)?; | ||
let upper_bound = std::cmp::min(n - buffer.len(), chunk_str.len()); | ||
|
||
if let Some(partial_chunk_str) = chunk_str.get(0..upper_bound) { | ||
buffer.push_str(partial_chunk_str); | ||
} else { | ||
// For whatever reason we are out of bounds. We should never land here | ||
// given the `std::cmp::min` usage, but I am being extra careful by not | ||
// using a slice index that would panic instead. | ||
return Err(WebhookResponseError::ChunkOutOfBoundsError( | ||
chunk_str.len(), | ||
upper_bound, | ||
)); | ||
} | ||
} | ||
|
||
Ok(buffer) | ||
} |
Oops, something went wrong.