Skip to content

Commit

Permalink
Remove reqwest dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
durch committed Apr 7, 2023
2 parents 4ee0461 + 81bd88c commit 10d4e3a
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 96 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Rust library for working with Amazon S3 or arbitrary S3 compatible APIs, fully c
### Intro

Modest interface towards Amazon S3, as well as S3 compatible object storage APIs such as Backblaze B2, Wasabi, Yandex, Minio or Google Cloud Storage.
Supports: `put`, `get`, `list`, `delete`, operations on `tags` and `location`, well as `head`.
Supports: `put`, `get`, `list`, `delete`, operations on `tags` and `location`, as well as `head`.

Additionally a dedicated `presign_get` `Bucket` method is available. This means you can upload to S3, and give the link to select people without having to worry about publicly accessible files on S3. This also means that you can give people
Additionally, a dedicated `presign_get` `Bucket` method is available. This means you can upload to S3, and give the link to select people without having to worry about publicly accessible files on S3. This also means that you can give people
a `PUT` presigned URL, meaning they can upload to a specific key in S3 for the duration of the presigned URL.

#### Quick Start
Expand Down Expand Up @@ -65,19 +65,19 @@ All runtimes support either `native-tls` or `rustls-tls`, there are features for

#### Path or subdomain style URLs and headers

`Bucket` struct provides constructors for `path-style` paths, `subdomain` style is the default. `Bucket` exposes methods for configuring and accessing `path-style` configuration. `blocking` feature will generate a `*_blocking` variant of all of the methods listed below.
`Bucket` struct provides constructors for `path-style` paths, `subdomain` style is the default. `Bucket` exposes methods for configuring and accessing `path-style` configuration. `blocking` feature will generate a `*_blocking` variant of all the methods listed below.

#### Buckets

| | |
| -------- | ---------------------------------------------------------------------------------- |
|----------|------------------------------------------------------------------------------------|
| `create` | [async](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.create) |
| `delete` | [async](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.delete) |

#### Presign

| | |
| -------- | --------------------------------------------------------------------------------------------------- |
|----------|-----------------------------------------------------------------------------------------------------|
| `POST` | [presign_put](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.presign_post) |
| `PUT` | [presign_put](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.presign_put) |
| `GET` | [presign_get](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.presign_get) |
Expand All @@ -89,7 +89,7 @@ There are a few different options for getting an object. `sync` and `async` meth
while `tokio` methods are generic over `tokio::io::AsyncWriteExt`.

| | |
| --------------------------- | --------------------------------------------------------------------------------------------------------------- |
|-----------------------------|-----------------------------------------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [get_object](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.get_object) |
| `async/sync/async-blocking` | [get_object_stream](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.get_object_stream) |
| `async/sync/async-blocking` | [get_object_to_writer](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.get_object_to_writer) |
Expand All @@ -99,40 +99,40 @@ while `tokio` methods are generic over `tokio::io::AsyncWriteExt`.
Each `GET` method has a `PUT` companion `sync` and `async` methods are generic over `std::io::Read`. `async` `stream` methods are generic over `futures_io::AsyncReadExt`, while `tokio` methods are generic over `tokio::io::AsyncReadExt`.

| | |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [put_object](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.put_object) |
| `async/sync/async-blocking` | [put_object_with_content_type](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.put_object_with_content_type) |
| `async/sync/async-blocking` | [put_object_stream](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.put_object_stream) |

#### List

| | |
| --------------------------- | ------------------------------------------------------------------------------- |
|-----------------------------|---------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [list](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.list) |

#### DELETE

| | |
| --------------------------- | ------------------------------------------------------------------------------------------------- |
|-----------------------------|---------------------------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [delete_object](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.delete_object) |

#### Location

| | |
| --------------------------- | --------------------------------------------------------------------------------------- |
|-----------------------------|-----------------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [location](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.location) |

#### Tagging

| | |
| --------------------------- | ----------------------------------------------------------------------------------------------------------- |
|-----------------------------|-------------------------------------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [put_object_tagging](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.put_object_tagging) |
| `async/sync/async-blocking` | [get_object_tagging](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.get_object_tagging) |

#### Head

| | |
| --------------------------- | --------------------------------------------------------------------------------------------- |
|-----------------------------|-----------------------------------------------------------------------------------------------|
| `async/sync/async-blocking` | [head_object](https://docs.rs/rust-s3/latest/s3/bucket/struct.Bucket.html#method.head_object) |

### Usage (in `Cargo.toml`)
Expand Down
18 changes: 9 additions & 9 deletions s3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-s3"
version = "0.34.0-beta1"
version = "0.34.0-beta2"
authors = ["Drazen Urch"]
description = "Rust library for working with AWS S3 and compatible object storage APIs"
repository = "https://github.com/durch/rust-s3"
Expand Down Expand Up @@ -57,14 +57,12 @@ futures-util = { version = "0.3", optional = true, features = ["io"] }
hex = "0.4"
hmac = "0.12"
http = "0.2"
hyper = { version = "0.14", default-features = false, features = ["client", "http1", "stream"], optional = true }
hyper-tls = { version = "0.5.0", default-features = false, optional = true }
log = "0.4"
maybe-async = { version = "0.2" }
md5 = "0.7"
percent-encoding = "2"
reqwest = { version = "0.11", default-features = false, features = [
"json",
"stream",
], optional = true }
serde = "1"
serde_derive = "1"
quick-xml = { version = "0.28", features = [ "serialize" ] }
Expand All @@ -76,22 +74,24 @@ surf = { version = "2", optional = true, default-features = false, features = [
tokio = { version = "1", features = [
"io-util",
], optional = true, default-features = false }
tokio-native-tls = { version = "0.3", optional = true }
native-tls = { version = "0.2", optional = true }
tokio-stream = { version = "0.1", optional = true }
url = "2"
minidom = { version = "0.15", optional = true }
bytes = { version = "1" }
block_on_proc = { version = "0.2", optional = true }

[features]
default = ["tags", "tokio-native-tls", "fail-on-err"]
with-tokio = ["reqwest", "tokio", "tokio/fs", "tokio-stream", "futures"]
default = ["tags", "use-tokio-native-tls", "fail-on-err"]
with-tokio = ["hyper", "hyper-tls", "tokio", "tokio/fs", "tokio-stream", "tokio-native-tls", "native-tls", "futures"]
async-std-native-tls = ["with-async-std", "aws-creds/native-tls"]
with-async-std = ["async-std", "surf", "futures-io", "futures-util", "futures"]
sync = ["attohttpc", "maybe-async/is_sync"]
no-verify-ssl = []
fail-on-err = []
tokio-native-tls = ["with-tokio", "reqwest/native-tls", "aws-creds/native-tls"]
tokio-rustls-tls = ["with-tokio", "reqwest/rustls-tls", "aws-creds/rustls-tls"]
use-tokio-native-tls = ["with-tokio", "aws-creds/native-tls"]
tokio-rustls-tls = ["with-tokio", "aws-creds/rustls-tls"]
sync-native-tls = ["sync", "aws-creds/native-tls", "attohttpc/tls"]
sync-native-tls-vendored = [ "sync", "aws-creds/native-tls-vendored", "attohttpc/tls-vendored" ]
sync-rustls-tls = ["sync", "aws-creds/rustls-tls", "attohttpc/tls-rustls"]
Expand Down
9 changes: 6 additions & 3 deletions s3/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub type Query = HashMap<String, String>;
#[cfg(feature = "with-async-std")]
use crate::request::async_std_backend::SurfRequest as RequestImpl;
#[cfg(feature = "with-tokio")]
use crate::request::tokio_backend::Reqwest as RequestImpl;
use crate::request::tokio_backend::HyperRequest as RequestImpl;

#[cfg(feature = "with-async-std")]
use futures_io::AsyncWrite;
Expand Down Expand Up @@ -2010,7 +2010,10 @@ impl Bucket {
Ok(())
} else {
let utf8_content = String::from_utf8(response_data.as_slice().to_vec())?;
Err(S3Error::Http(response_data.status_code(), utf8_content))
Err(S3Error::HttpFailWithBody(
response_data.status_code(),
utf8_content,
))
}
}

Expand Down Expand Up @@ -2038,7 +2041,7 @@ impl Bucket {
/// requests, or no (infinity) timeout if `None`. Defaults to
/// 30 seconds.
///
/// Only the attohttpc and the Reqwest backends obey this option;
/// Only the [`attohttpc`] and the [`hyper`] backends obey this option;
/// async code may instead await with a timeout.
pub fn set_request_timeout(&mut self, timeout: Option<Duration>) {
self.request_timeout = timeout;
Expand Down
12 changes: 9 additions & 3 deletions s3/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum S3Error {
#[error("Max expiration for presigned URLs is one week, or 604.800 seconds, got {0} instead")]
MaxExpiry(u32),
#[error("Got HTTP {0} with content '{1}'")]
Http(u16, String),
HttpFailWithBody(u16, String),
#[error("Http request returned a non 2** code")]
HttpFail,
#[error("aws-creds: {0}")]
Expand All @@ -21,8 +21,14 @@ pub enum S3Error {
#[error("io: {0}")]
Io(#[from] std::io::Error),
#[cfg(feature = "with-tokio")]
#[error("reqwest: {0}")]
Reqwest(#[from] reqwest::Error),
#[error("http: {0}")]
Http(#[from] http::Error),
#[cfg(feature = "with-tokio")]
#[error("hyper: {0}")]
Hyper(#[from] hyper::Error),
#[cfg(feature = "with-tokio")]
#[error("native-tls: {0}")]
NativeTls(#[from] native_tls::Error),
#[error("header to string: {0}")]
HeaderToStr(#[from] http::header::ToStrError),
#[error("from utf8: {0}")]
Expand Down
2 changes: 1 addition & 1 deletion s3/src/request/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<'a> Request for AttoRequest<'a> {
if cfg!(feature = "fail-on-err") && !response.status().is_success() {
let status = response.status().as_u16();
let text = response.text()?;
return Err(S3Error::Http(status, text));
return Err(S3Error::HttpFailWithBody(status, text));
}

Ok(response)
Expand Down
Loading

0 comments on commit 10d4e3a

Please sign in to comment.