Skip to content

Commit

Permalink
Use reqwest::* instead of http::* where possible
Browse files Browse the repository at this point in the history
Currently blocked on XAMPPRocky/octocrab#492
  • Loading branch information
mre committed Dec 4, 2023
1 parent c31bd30 commit 7431a73
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/builder/builder.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use http::header::{self, HeaderMap};
use http::StatusCode;
use lychee_lib::{ClientBuilder, Result};
use regex::RegexSet;
use reqwest::Method;
use reqwest::StatusCode;
use std::{collections::HashSet, time::Duration};

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion lychee-bin/src/archive/wayback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use serde::de::Error as SerdeError;
use serde::{Deserialize, Deserializer};

use http::StatusCode;
use reqwest::StatusCode;
use reqwest::{Error, Url};
static WAYBACK_URL: Lazy<Url> =
Lazy::new(|| Url::parse("https://archive.org/wayback/available").unwrap());
Expand Down
2 changes: 1 addition & 1 deletion lychee-bin/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::options::Config;
use crate::parse::{parse_duration_secs, parse_headers, parse_remaps};
use anyhow::{Context, Result};
use http::StatusCode;
use lychee_lib::{Client, ClientBuilder};
use regex::RegexSet;
use reqwest::StatusCode;
use reqwest_cookie_store::CookieStoreMutex;
use std::sync::Arc;
use std::{collections::HashSet, str::FromStr};
Expand Down
4 changes: 2 additions & 2 deletions lychee-bin/src/formatters/stats/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::{

use super::StatsFormatter;
use anyhow::Result;
use http::StatusCode;
use lychee_lib::{InputSource, ResponseBody, Status};
use reqwest::StatusCode;
use std::fmt::Write;
use tabled::{
settings::{object::Segment, Alignment, Modify, Style},
Expand Down Expand Up @@ -156,8 +156,8 @@ impl StatsFormatter for Markdown {
#[cfg(test)]
mod tests {

use http::StatusCode;
use lychee_lib::{CacheStatus, InputSource, Response, ResponseBody, Status, Uri};
use reqwest::StatusCode;
use reqwest::Url;

use crate::archive::Suggestion;
Expand Down
2 changes: 1 addition & 1 deletion lychee-bin/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ mod tests {
use pretty_assertions::assert_eq;
use std::collections::{HashMap, HashSet};

use http::StatusCode;
use lychee_lib::{ErrorKind, InputSource, Response, ResponseBody, Status, Uri};
use reqwest::StatusCode;
use reqwest::Url;

use super::ResponseStats;
Expand Down
4 changes: 2 additions & 2 deletions lychee-bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ mod cli {

use assert_cmd::Command;
use assert_json_diff::assert_json_include;
use http::StatusCode;
use lychee_lib::{InputSource, ResponseBody};
use predicates::str::{contains, is_empty};
use pretty_assertions::assert_eq;
use regex::Regex;
use reqwest::StatusCode;
use serde::Serialize;
use serde_json::Value;
use tempfile::NamedTempFile;
Expand All @@ -32,7 +32,7 @@ mod cli {
macro_rules! mock_server {
($status:expr $(, $func:tt ($($arg:expr),*))*) => {{
let mock_server = wiremock::MockServer::start().await;
let response_template = wiremock::ResponseTemplate::new(http::StatusCode::from($status));
let response_template = wiremock::ResponseTemplate::new(reqwest::StatusCode::from($status));
let template = response_template$(.$func($($arg),*))*;
wiremock::Mock::given(wiremock::matchers::method("GET")).respond_with(template).mount(&mock_server).await;
mock_server
Expand Down
24 changes: 13 additions & 11 deletions lychee-lib/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ use std::{collections::HashSet, path::Path, sync::Arc, time::Duration};
#[cfg(all(feature = "email-check", feature = "native-tls"))]
use check_if_email_exists::{check_email, CheckEmailInput, Reachable};
use headers::authorization::Credentials;
use http::{
header::{HeaderMap, HeaderValue, AUTHORIZATION},
StatusCode,
};
use log::{debug, warn};
use octocrab::Octocrab;
use regex::RegexSet;
use reqwest::{header, redirect, Url};
use reqwest::{
header::{HeaderMap, HeaderValue, AUTHORIZATION},
redirect, StatusCode, Url,
};
use reqwest_cookie_store::CookieStoreMutex;
use secrecy::{ExposeSecret, SecretString};
use typed_builder::TypedBuilder;
Expand Down Expand Up @@ -306,17 +305,18 @@ impl ClientBuilder {
..
} = self;

if let Some(prev_user_agent) =
headers.insert(header::USER_AGENT, HeaderValue::try_from(&user_agent)?)
{
if let Some(prev_user_agent) = headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::try_from(&user_agent)?,
) {
debug!(
"Found user-agent in headers: {}. Overriding it with {user_agent}.",
prev_user_agent.to_str().unwrap_or("�"),
);
};

headers.insert(
header::TRANSFER_ENCODING,
reqwest::header::TRANSFER_ENCODING,
HeaderValue::from_static("chunked"),
);

Expand Down Expand Up @@ -765,8 +765,10 @@ mod tests {
time::{Duration, Instant},
};

use http::{header::HeaderMap, StatusCode};
use reqwest::header;
use reqwest::{
header::{self, HeaderMap},
StatusCode,
};
use tempfile::tempdir;
use wiremock::matchers::path;

Expand Down
2 changes: 1 addition & 1 deletion lychee-lib/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Collector {
mod tests {
use std::{collections::HashSet, convert::TryFrom, fs::File, io::Write};

use http::StatusCode;
use reqwest::StatusCode;
use reqwest::Url;

use super::*;
Expand Down
7 changes: 2 additions & 5 deletions lychee-lib/src/quirks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use header::HeaderValue;
use http::header;
use once_cell::sync::Lazy;
use regex::Regex;
use reqwest::{Request, Url};
use reqwest::{header, Request, Url};
use std::collections::HashMap;

static CRATES_PATTERN: Lazy<Regex> =
Expand Down Expand Up @@ -88,9 +87,7 @@ impl Quirks {

#[cfg(test)]
mod tests {
use header::HeaderValue;
use http::{header, Method};
use reqwest::{Request, Url};
use reqwest::{Method, Request, Url, header::{self, HeaderValue}};

use super::Quirks;

Expand Down
5 changes: 3 additions & 2 deletions lychee-lib/src/retry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;

use http::StatusCode;
use reqwest::StatusCode;

use crate::{ErrorKind, Status};

Expand Down Expand Up @@ -102,7 +102,8 @@ impl RetryExt for ErrorKind {
backtrace: _,
}) = self.github_error()
{
source.should_retry()
todo!("blocked on https://github.com/XAMPPRocky/octocrab/issues/492");
// source.should_retry()
} else {
false
}
Expand Down
2 changes: 1 addition & 1 deletion lychee-lib/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{ClientBuilder, ErrorKind, Request, Uri};
macro_rules! mock_server {
($status:expr $(, $func:tt ($($arg:expr),*))*) => {{
let mock_server = wiremock::MockServer::start().await;
let response_template = wiremock::ResponseTemplate::new(http::StatusCode::from($status));
let response_template = wiremock::ResponseTemplate::new(reqwest::StatusCode::from($status));
let template = response_template$(.$func($($arg),*))*;
wiremock::Mock::given(wiremock::matchers::method("GET")).respond_with(template).mount(&mock_server).await;
mock_server
Expand Down
2 changes: 1 addition & 1 deletion lychee-lib/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub enum ErrorKind {
/// A possible error when converting a `HeaderValue` from a string or byte
/// slice.
#[error("Header could not be parsed.")]
InvalidHeader(#[from] http::header::InvalidHeaderValue),
InvalidHeader(#[from] reqwest::header::InvalidHeaderValue),

/// The given string can not be parsed into a valid base URL or base directory
#[error("Error with base dir `{0}` : {1}")]
Expand Down
2 changes: 1 addition & 1 deletion lychee-lib/src/types/response.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::fmt::Display;

use http::StatusCode;
use reqwest::StatusCode;
use serde::Serialize;

use crate::{InputSource, Status, Uri};
Expand Down
4 changes: 2 additions & 2 deletions lychee-lib/src/types/status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashSet, fmt::Display};

use http::StatusCode;
use reqwest::Response;
use reqwest::StatusCode;
use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};

Expand Down Expand Up @@ -303,7 +303,7 @@ impl From<reqwest::Error> for Status {
#[cfg(test)]
mod tests {
use crate::{CacheStatus, ErrorKind, Status};
use http::StatusCode;
use reqwest::StatusCode;

#[test]
fn test_status_serialization() {
Expand Down

0 comments on commit 7431a73

Please sign in to comment.