File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ use std:: env;
2+
13use reqwest:: { Client , ClientBuilder } ;
24
35#[ cfg( not( any( target_os = "macos" , target_os = "windows" ) ) ) ]
@@ -12,10 +14,25 @@ pub fn build_client() -> Result<Client, Box<dyn std::error::Error>> {
1214 builder = builder. add_root_certificate ( cert) ;
1315 }
1416
17+ builder = builder. user_agent ( get_user_agent ( ) ) ;
18+
1519 Ok ( builder. build ( ) ?)
1620}
1721
1822#[ cfg( any( target_os = "macos" , target_os = "windows" ) ) ]
1923pub fn build_client ( ) -> Result < Client , Box < dyn std:: error:: Error > > {
20- Ok ( ClientBuilder :: new ( ) . build ( ) ?)
24+ Ok ( ClientBuilder :: new ( ) . user_agent ( get_user_agent ( ) ) . build ( ) ?)
25+ }
26+
27+ fn get_user_agent ( ) -> String {
28+ let version = env ! ( "CARGO_PKG_VERSION" ) ;
29+ let os = std:: env:: consts:: OS ;
30+ let arch = std:: env:: consts:: ARCH ;
31+ let group = env:: var ( "PKGX_USER_AGENT_GROUP" ) ;
32+ let name = if group. is_ok ( ) {
33+ format ! ( "pkgx[{}]" , group. unwrap( ) )
34+ } else {
35+ "pkgx" . to_string ( )
36+ } ;
37+ format ! ( "{name}/{version} ({os}; {arch})" )
2138}
You can’t perform that action at this time.
0 commit comments