Skip to content

Commit a7514b4

Browse files
committed
chore: Replace attohttpc with reqwest
1 parent 93c2132 commit a7514b4

File tree

11 files changed

+22
-20
lines changed

11 files changed

+22
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- A way to customize resolving remote stylesheets.
88

9+
### Changed
10+
11+
- Replace `attohttpc` with `reqwest` to simplify implementing non-blocking stylesheet resolving in the future release.
12+
913
## [0.12.0] - 2023-12-28
1014

1115
### Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn main() -> css_inline::Result<()> {
8888
let inliner = css_inline::CSSInliner::options()
8989
.load_remote_stylesheets(false)
9090
.build();
91-
let inlined = inliner.inline(HTML);
91+
let inlined = inliner.inline(HTML)?;
9292
// Do something with inlined HTML, e.g. send an email
9393
Ok(())
9494
}

bindings/javascript/__test__/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test("invalid href", (t) => {
4949
);
5050
});
5151
t.is(error.code, "GenericFailure");
52-
t.is(error.message, "Invalid base URL: http:");
52+
t.is(error.message, "builder error: empty host: http:");
5353
});
5454

5555
test("invalid style", (t) => {

bindings/python/tests-py/test_inlining.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_invalid_base_url():
9595

9696

9797
def test_invalid_href():
98-
with pytest.raises(ValueError, match="Invalid base URL: http:"):
98+
with pytest.raises(ValueError, match="builder error: empty host: http:"):
9999
css_inline.inline(
100100
"""<html>
101101
<head>

bindings/ruby/spec/css_inline_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def make_html(style, body)
7979
</body>
8080
</html>
8181
''')
82-
}.to raise_error('Invalid base URL: http:')
82+
}.to raise_error('builder error: empty host: http:')
8383
end
8484

8585
it 'Shows the CSS parsing errors' do

css-inline/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,16 @@ name = "css-inline"
2424
[features]
2525
default = ["cli", "http", "file"]
2626
cli = ["pico-args", "rayon"]
27-
http = ["attohttpc"]
27+
http = ["reqwest"]
2828
file = []
2929

3030
[dependencies]
31-
attohttpc = { version = "0.24", default-features = false, features = [
32-
"compress",
33-
"tls-rustls",
34-
], optional = true }
3531
cssparser = "0.31.2"
3632
html5ever = "0.26.0"
3733
indexmap = "2.1"
3834
pico-args = { version = "0.3", optional = true }
3935
rayon = { version = "1.7", optional = true }
36+
reqwest = { version = "0.11.23", optional = true, default-features = false, features = ["rustls-tls", "blocking"] }
4037
rustc-hash = "1.1.0"
4138
selectors = "0.25.0"
4239
smallvec = "1"

css-inline/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum InlineError {
2323
#[cfg(feature = "http")]
2424
Network {
2525
/// Original network error.
26-
error: attohttpc::Error,
26+
error: reqwest::Error,
2727
/// The stylesheet location caused the error.
2828
location: String,
2929
},

css-inline/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ pub fn inline(html: &str) -> Result<String> {
403403
}
404404

405405
/// Shortcut for inlining CSS with default parameters and writing the output to a generic writer.
406+
///
406407
/// # Errors
407408
///
408409
/// Inlining might fail for the following reasons:

css-inline/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use css_inline::DefaultStylesheetResolver;
2-
use std::sync::Arc;
3-
41
#[cfg(not(feature = "cli"))]
52
fn main() {
63
eprintln!("`css-inline` CLI is only available with the `cli` feature");
@@ -9,7 +6,7 @@ fn main() {
96

107
#[cfg(feature = "cli")]
118
fn main() -> Result<(), Box<dyn std::error::Error>> {
12-
use css_inline::{CSSInliner, InlineOptions};
9+
use css_inline::{CSSInliner, DefaultStylesheetResolver, InlineOptions};
1310
use rayon::prelude::*;
1411
use std::{
1512
borrow::Cow,
@@ -18,7 +15,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1815
fs::{read_to_string, File},
1916
io::{self, Read, Write},
2017
path::Path,
21-
sync::atomic::{AtomicI32, Ordering},
18+
sync::{
19+
atomic::{AtomicI32, Ordering},
20+
Arc,
21+
},
2222
};
2323

2424
const VERSION_MESSAGE: &[u8] =

css-inline/src/resolver.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ impl StylesheetResolver for DefaultStylesheetResolver {
7979
error,
8080
location: url.to_string(),
8181
};
82-
let request =
83-
attohttpc::RequestBuilder::try_new(attohttpc::Method::GET, url).map_err(into_error)?;
84-
let response = request.send().map_err(into_error)?;
85-
response.text().map_err(into_error)
82+
reqwest::blocking::get(url)
83+
.map_err(into_error)?
84+
.text()
85+
.map_err(into_error)
8686
}
8787
}

0 commit comments

Comments
 (0)