Repository navigation
Conversation
|
Update: I renamed |
- Rename Checker to Client (in line with reqwest::Client) - Rename CheckerBuilder to ClientBuilder (in line with reqwest::ClientBuilder) - Remove crate visibility for types that will be exposed in the library
Turns out reqwest also accepts any request method and dutifully makes a request to the server. The servers might respond with an HTTP status code > 2xx, but apart from that, these requests are totally valid. I don't know why this was done, but I assume because of compatibility with potential future versions of the HTTP spec. In any case, I'm planning to lift the restrictrions on accepting only `GET` and `HEAD` requests because of this and removing the test.
|
Removed test for invalid method Turns out reqwest also accepts any request method and dutifully makes a request For example, the following code runs without any problems: use reqwest;
#[tokio::main]
async fn main() {
let client = reqwest::Client::new();
let fake_method = reqwest::Method::from_bytes(b"LOL").unwrap();
let req = client
.request(fake_method, "https://example.com")
.build()
.unwrap();
println!("{:?}", client.execute(req).await);
}The response fails with a 501, but it is a valid request nonetheless. Ok(Response { url: Url { scheme: "https", host: Some(Domain("example.com")),
port: None, path: "/", query: None, fragment: None }, status: 501, headers:
{"content-type": "text/html", "content-length": "357", "connection": "close",
"date": "Thu, 19 Nov 2020 23:33:23 GMT", "server": "ECSF (nyb/1D25)"} })I don't know why this was done, but I assume because of compatibility with |
This code certainly be improved
pawroman
left a comment
There was a problem hiding this comment.
Looks good overall, great work! Left a few (mostly minor) remarks.
After some tinkering I realized that it's much easier if we decouple the link checking from the progress reporting.
Great idea 👍
Shall we rename Checker and CheckerBuilder? I really don't like those names anymore. Was considering Lychee, but it has nothing to do with the functionality. Request sounds too generic. What do people think of Validator?
No strong opinions here, Validator is as good a name as any 😉
|
Ticked off the last points on the todo list:
If someone wants to try, check Right now, the bootup is slow with a lot of URLs. The URL parsing on the file
It's not idiomatic. We use
I'd say Thanks for the review @pawroman. 🚀 |
pawroman
left a comment
There was a problem hiding this comment.
Looks good 👍
I just have some doubts whether we need the top 1 million domains file which is 22.5 MB in size. This is going to negatively effect contribution experience. Maybe we could shorten and/or compress it?
Also, since it seems not to be used, maybe we could move it to a separate repository for now?
Oh yeah absolutely. I was using it for a bigger test locally just to see if performance was okay. Fun fact: The internet is a weird place and many URLs in that list are either not available anymore (DNS error), don't support HTTPS or trigger redirect loops. I was kinda surprised and thought I hit bugs in lychee but actually those errors turned out to be valid — and that's for the top 1 million sites on the web; I don't even want to know about the rest of them. Did some final cleanup for the status reporting based on your last comments. |
This implements a basic builder for the
Checkerstruct as discussed in #12.derive_builderand uses a custombuildmethod to instantiate the more elaborate fields likereqwest::Client.progress_bar. After some tinkering I realized that it's much easier if we decouple the link checking from the progress reporting. So I usedasync_channelin between the two. There is a newWorkerstruct, which reads from the channel and runs the checker. This way the checker does not even know that the channel exists, which allows us to put the checker into its own crate eventually for use as a library.TODO:
checkfutures at once and then join them in the end. Don't know how this is done yet. Perhaps withfutures::select? Ideas very welcome.tokio::spawn(async move { woker.listen().await } );is really idiomatic. I get a warning that I'm not using theResult, but I don't know how. This can probably be simplified totokio::spawn(worker.listen());.TBD:
CheckerandCheckerBuilder? I really don't like those names anymore. Was consideringLychee, but it has nothing to do with the functionality.Requestsounds too generic. What do people think ofValidator?