@@ -30,6 +30,13 @@ pub fn message(res: &Result) -> String {
3030// Keep history of link checks so a rebuild doesn't have to check again
3131static LINKS : Lazy < Arc < RwLock < HashMap < String , Result > > > > =
3232 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+ } ) ;
3340
3441pub fn check_url ( url : & str , config : & LinkChecker ) -> Result {
3542 {
@@ -44,15 +51,11 @@ pub fn check_url(url: &str, config: &LinkChecker) -> Result {
4451 headers. append ( ACCEPT , "*/*" . parse ( ) . unwrap ( ) ) ;
4552
4653 // 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" ) ;
5154
5255 let check_anchor = !config. skip_anchor_prefixes . iter ( ) . any ( |prefix| url. starts_with ( prefix) ) ;
5356
5457 // 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 ( ) {
5659 Ok ( ref mut response) if check_anchor && has_anchor ( url) => {
5760 let body = {
5861 let mut buf: Vec < u8 > = vec ! [ ] ;
0 commit comments