feat: Add Cloudflare bypass test and enable native-tls-alpn feature… - #36
Merged
Conversation
Contributor
Author
|
I've noticed this issue in on more than a few websites. The application/ld+json section is present in the headers (verified via cUrl and manual inspection of page source) but Cloudflare was blocking the I looked around for reasons why and found this post: seanmonstar/reqwest#2227 and specifically this comment seanmonstar/reqwest#2227 (reply in thread) So, I went that route. It seems like a simple fix for a problem that will affect more than a few websites. This is my first PR to this project. Please let me know if I should do things differently 😊 |
Member
|
Wow, that's a simple fix for that annoying issue, great find! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Issue
The website is protected by Cloudflare, which was blocking the default reqwest HTTP client used by the application. This resulted in the application receiving a "Just a moment..." challenge page instead of the actual recipe content, causing the JSON-LD extractor to fail.
The Fix
The root cause was identified as a known issue with reqwest's default TLS configuration when interacting with Cloudflare's HTTP/2 implementation. The fix involved:
Enabling native-tls-alpn: This feature ensures correct Application-Layer Protocol Negotiation (ALPN) for HTTP/2, which Cloudflare requires to validate the client.
Changes
Cargo.toml
Enabled native-tls-alpn feature for reqwest.
Verification
I verified the fix by running the application against the reported URL:
Result: The application successfully extracted the recipe.
Automated Test
I also added a new integration test
tests/test_cloudflare_bypass.rsto ensure this remains fixed. You can run it with: