@@ -30,6 +30,13 @@ pub fn message(res: &Result) -> String {
30
30
// Keep history of link checks so a rebuild doesn't have to check again
31
31
static LINKS : Lazy < Arc < RwLock < HashMap < String , Result > > > > =
32
32
Lazy :: new ( || Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ) ;
33
+ // Make sure to create only a single Client so that we can reuse the connections
34
+ static CLIENT : Lazy < Client > = Lazy :: new ( || {
35
+ Client :: builder ( )
36
+ . user_agent ( concat ! ( env!( "CARGO_PKG_NAME" ) , "/" , env!( "CARGO_PKG_VERSION" ) ) )
37
+ . build ( )
38
+ . expect ( "reqwest client build" )
39
+ } ) ;
33
40
34
41
pub fn check_url ( url : & str , config : & LinkChecker ) -> Result {
35
42
{
@@ -44,15 +51,11 @@ pub fn check_url(url: &str, config: &LinkChecker) -> Result {
44
51
headers. append ( ACCEPT , "*/*" . parse ( ) . unwrap ( ) ) ;
45
52
46
53
// TODO: pass the client to the check_url, do not pass the config
47
- let client = Client :: builder ( )
48
- . user_agent ( concat ! ( env!( "CARGO_PKG_NAME" ) , "/" , env!( "CARGO_PKG_VERSION" ) ) )
49
- . build ( )
50
- . expect ( "reqwest client build" ) ;
51
54
52
55
let check_anchor = !config. skip_anchor_prefixes . iter ( ) . any ( |prefix| url. starts_with ( prefix) ) ;
53
56
54
57
// Need to actually do the link checking
55
- let res = match client . get ( url) . headers ( headers) . send ( ) {
58
+ let res = match CLIENT . get ( url) . headers ( headers) . send ( ) {
56
59
Ok ( ref mut response) if check_anchor && has_anchor ( url) => {
57
60
let body = {
58
61
let mut buf: Vec < u8 > = vec ! [ ] ;
0 commit comments