@@ -8,6 +8,7 @@ use eth2::{
8
8
Error :: ServerMessage ,
9
9
StatusCode , Timeouts ,
10
10
mixin:: { RequestAccept , ResponseForkName , ResponseOptional } ,
11
+ reqwest:: Method ,
11
12
reqwest:: RequestBuilder ,
12
13
types:: {
13
14
BlockId as CoreBlockId , ForkChoiceNode , ProduceBlockV3Response , StateId as CoreStateId , * ,
@@ -35,6 +36,7 @@ use state_processing::per_slot_processing;
35
36
use state_processing:: state_advance:: partial_state_advance;
36
37
use std:: convert:: TryInto ;
37
38
use std:: sync:: Arc ;
39
+ use std:: sync:: Mutex ;
38
40
use tokio:: time:: Duration ;
39
41
use tree_hash:: TreeHash ;
40
42
use types:: application_domain:: ApplicationDomain ;
@@ -43,6 +45,7 @@ use types::{
43
45
MainnetEthSpec , RelativeEpoch , SelectionProof , SignedRoot , SingleAttestation , Slot ,
44
46
attestation:: AttestationBase ,
45
47
} ;
48
+ use warp:: Filter ;
46
49
47
50
type E = MainnetEthSpec ;
48
51
@@ -6733,6 +6736,33 @@ impl ApiTester {
6733
6736
}
6734
6737
self
6735
6738
}
6739
+
6740
+ async fn test_user_agent ( self ) -> Self {
6741
+ let captured: Arc < Mutex < Option < String > > > = Arc :: new ( Mutex :: new ( None ) ) ;
6742
+ let captured_filter = captured. clone ( ) ;
6743
+
6744
+ // Warp route: capture User-Agent header
6745
+ let route = warp:: any ( )
6746
+ . and ( warp:: header:: optional :: < String > ( "user-agent" ) )
6747
+ . map ( move |ua : Option < String > | {
6748
+ * captured_filter. lock ( ) . unwrap ( ) = ua;
6749
+ warp:: reply ( )
6750
+ } ) ;
6751
+
6752
+ // Start ephemeral server
6753
+ let ( addr, server) = warp:: serve ( route) . bind_ephemeral ( ( [ 127 , 0 , 0 , 1 ] , 0 ) ) ;
6754
+ tokio:: spawn ( server) ;
6755
+
6756
+ // Make a request (simulate Lighthouse client)
6757
+ let url = format ! ( "http://{}/" , addr) ;
6758
+ let _client = self . client . create_request ( Method :: GET , & url) . await ;
6759
+
6760
+ // Check captured User-Agent
6761
+ let ua = captured. lock ( ) . unwrap ( ) . clone ( ) . unwrap ( ) ;
6762
+ assert_eq ! ( ua, lighthouse_version:: DEFAULT_USER_AGENT ) ;
6763
+
6764
+ self
6765
+ }
6736
6766
}
6737
6767
6738
6768
async fn poll_events < S : Stream < Item = Result < EventKind < E > , eth2:: Error > > + Unpin , E : EthSpec > (
@@ -7882,3 +7912,8 @@ async fn get_beacon_rewards_blocks_electra() {
7882
7912
. test_beacon_block_rewards_electra ( )
7883
7913
. await ;
7884
7914
}
7915
+
7916
+ #[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
7917
+ async fn test_user_agent ( ) {
7918
+ ApiTester :: new ( ) . await . test_user_agent ( ) . await ;
7919
+ }
0 commit comments