Skip to content

Commit 07e4cc2

Browse files
committed
feat: Add Cloudflare bypass test and enable native-tls-alpn feature for reqwest.
1 parent b590cc5 commit 07e4cc2

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ env_logger = "0.11"
2424
html-escape = "0.2"
2525
log = "0.4"
2626
openssl = { version = "0.10", features = ["vendored"] }
27-
reqwest = { version = "0.12", features = ["blocking", "json", "native-tls-vendored"] }
27+
reqwest = { version = "0.12", features = ["blocking", "json", "native-tls-vendored", "native-tls-alpn"] }
2828
scraper = "0.20"
2929
serde = { version = "1.0", features = ["derive"] }
3030
serde_json = "1.0"

tests/test_cloudflare_bypass.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use cooklang_import::fetch_recipe;
2+
use std::env;
3+
4+
#[tokio::test]
5+
#[ignore] // This test requires network access and is subject to external site changes
6+
async fn test_acouplecooks_cloudflare_bypass() {
7+
// Enable logging to see debug output if needed
8+
env::set_var("RUST_LOG", "debug");
9+
let _ = env_logger::try_init();
10+
11+
let url = "https://www.acouplecooks.com/apple-cranberry-crisp/";
12+
13+
println!("Attempting to fetch recipe from: {}", url);
14+
15+
match fetch_recipe(url).await {
16+
Ok(recipe) => {
17+
println!("Successfully bypassed Cloudflare and parsed recipe!");
18+
println!("Name: {}", recipe.name);
19+
20+
// Verify we got the correct recipe
21+
assert_eq!(recipe.name, "Apple Cranberry Crisp");
22+
assert!(!recipe.content.is_empty());
23+
24+
// Verify some specific content to ensure we didn't just get a title from metadata
25+
assert!(recipe.content.contains("cranberries"));
26+
assert!(recipe.content.contains("sugar"));
27+
28+
// Check metadata
29+
assert_eq!(recipe.metadata.get("author").unwrap(), "Sonja Overhiser");
30+
assert!(recipe.metadata.contains_key("cook time"));
31+
}
32+
Err(e) => {
33+
panic!("Failed to fetch recipe (Cloudflare bypass failed?): {}", e);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)