@@ -15,7 +15,7 @@ use std::time::{Duration, SystemTime};
1515
1616use async_trait:: async_trait;
1717use bytes:: { Buf , Bytes } ;
18- use http:: header:: { CONTENT_TYPE , RETRY_AFTER } ;
18+ use http:: header:: { CONTENT_TYPE , RETRY_AFTER , USER_AGENT } ;
1919use http:: { Method , Request , Response , StatusCode } ;
2020use http_body:: { Frame , SizeHint } ;
2121use http_body_util:: BodyExt ;
@@ -61,11 +61,12 @@ struct Client {
6161
6262impl Client {
6363 async fn new ( directory_url : String , http : Box < dyn HttpClient > ) -> Result < Self , Error > {
64- let req = Request :: builder ( )
64+ let request = Request :: builder ( )
6565 . uri ( & directory_url)
66+ . header ( USER_AGENT , CRATE_USER_AGENT )
6667 . body ( BodyWrapper :: default ( ) )
6768 . expect ( "infallible error should not occur" ) ;
68- let rsp = http. request ( req ) . await ?;
69+ let rsp = http. request ( request ) . await ?;
6970 let body = rsp. body ( ) . await . map_err ( Error :: Other ) ?;
7071 Ok ( Client {
7172 http,
@@ -123,6 +124,7 @@ impl Client {
123124 let request = Request :: builder ( )
124125 . method ( Method :: POST )
125126 . uri ( url)
127+ . header ( USER_AGENT , CRATE_USER_AGENT )
126128 . header ( CONTENT_TYPE , JOSE_JSON )
127129 . body ( BodyWrapper :: from ( serde_json:: to_vec ( & body) ?) ) ?;
128130
@@ -137,6 +139,7 @@ impl Client {
137139 let request = Request :: builder ( )
138140 . method ( Method :: HEAD )
139141 . uri ( & self . directory . new_nonce )
142+ . header ( USER_AGENT , CRATE_USER_AGENT )
140143 . body ( BodyWrapper :: default ( ) )
141144 . expect ( "infallible error should not occur" ) ;
142145
@@ -400,6 +403,7 @@ mod crypto {
400403 }
401404}
402405
406+ const CRATE_USER_AGENT : & str = concat ! ( "instant-acme/" , env!( "CARGO_PKG_VERSION" ) ) ;
403407const JOSE_JSON : & str = "application/jose+json" ;
404408const REPLAY_NONCE : & str = "Replay-Nonce" ;
405409
0 commit comments