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: Use reqwest blocking client instead of ureq #1853

Merged
merged 4 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/service_test_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
OPENDAL_S3_ENDPOINT: ${{ secrets.OPENDAL_S3_ENDPOINT }}
OPENDAL_S3_ACCESS_KEY_ID: ${{ secrets.OPENDAL_S3_ACCESS_KEY_ID }}
OPENDAL_S3_SECRET_ACCESS_KEY: ${{ secrets.OPENDAL_S3_SECRET_ACCESS_KEY }}
OPENDAL_S3_REGION: ap-northeast-1

aws_s3_with_virtual_host:
runs-on: ubuntu-latest
Expand All @@ -77,6 +78,7 @@ jobs:
OPENDAL_S3_ACCESS_KEY_ID: ${{ secrets.OPENDAL_S3_ACCESS_KEY_ID }}
OPENDAL_S3_SECRET_ACCESS_KEY: ${{ secrets.OPENDAL_S3_SECRET_ACCESS_KEY }}
OPENDAL_S3_ENABLE_VIRTUAL_HOST_STYLE: on
OPENDAL_S3_REGION: ap-northeast-1

aws_s3_with_sse_c:
runs-on: ubuntu-latest
Expand All @@ -100,6 +102,7 @@ jobs:
OPENDAL_S3_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM: AES256
OPENDAL_S3_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY: MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA=
OPENDAL_S3_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5: zZ5FnqcIqUjVwvWmyog4zw==
OPENDAL_S3_REGION: ap-northeast-1

minio_s3:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ reqsign = "0.8.5"
reqwest = { version = "0.11.13", features = [
"multipart",
"stream",
"blocking"
], default-features = false }
rocksdb = { version = "0.20.1", default-features = false, optional = true }
serde = { version = "1", features = ["derive"] }
Expand Down
55 changes: 30 additions & 25 deletions core/src/raw/http_util/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use std::cmp::min;
use std::cmp::Ordering;
use std::io;
use std::io::Read;
use std::io::Write;
use std::task::Context;
use std::task::Poll;

Expand All @@ -41,8 +39,6 @@ pub enum Body {
Empty,
/// Body with bytes.
Bytes(Bytes),
/// Body with a Reader.
Reader(Box<dyn Read + Send>),
}

impl Default for Body {
Expand All @@ -54,35 +50,44 @@ impl Default for Body {
impl Body {
/// Consume the entire body.
pub fn consume(self) -> Result<()> {
if let Body::Reader(mut r) = self {
std::io::copy(&mut r, &mut std::io::sink()).map_err(|err| {
Error::new(ErrorKind::Unexpected, "consuming response")
.with_operation("http_util::Body::consume")
.set_source(err)
})?;
}

Ok(())
}
}

impl Read for Body {
fn read(&mut self, mut buf: &mut [u8]) -> io::Result<usize> {
match self {
Body::Empty => Ok(0),
Body::Bytes(bs) => {
let size = min(bs.len(), buf.len());
let rbs = bs.split_to(size);
bs.advance(size);

buf.write_all(&rbs).expect("write all must succeed");
Ok(size)
}
Body::Reader(r) => r.read(buf),
impl From<Body> for reqwest::blocking::Body {
fn from(v: Body) -> Self {
match v {
Body::Empty => reqwest::blocking::Body::from(""),
Body::Bytes(bs) => reqwest::blocking::Body::from(bs),
}
}
}

/// IncomingBody carries the content returned by remote servers.
///
/// # Notes
///
/// Client SHOULD NEVER construct this body.
pub struct IncomingBody {
/// # TODO
///
/// hyper returns `impl Stream<Item = crate::Result<Bytes>>` but we can't
/// write the types in stable. So we will box here.
///
/// After [TAIT](https://rust-lang.github.io/rfcs/2515-type_alias_impl_trait.html)
/// has been stable, we can change `IncomingAsyncBody` into `IncomingAsyncBody<S>`.
#[allow(unused)]
inner: reqwest::blocking::Response,
#[allow(unused)]
size: Option<u64>,
}

impl IncomingBody {
pub fn new(resp: reqwest::blocking::Response, size: Option<u64>) -> Self {
IncomingBody { inner: resp, size }
}
}

/// Body used in async HTTP requests.
pub enum AsyncBody {
/// An empty body.
Expand Down
Loading