@@ -11,30 +11,37 @@ use rustls::{ClientConfig, ClientConnection, RootCertStore, StreamOwned};
1111use crate :: {
1212 event:: EventBus ,
1313 outbound:: ProxiedTcpStream ,
14- probe:: ProbeTarget ,
14+ probe:: { ProbeProtocol , ProbeTarget } ,
1515 resolver:: trace:: { classify_runtime_error, elapsed_ms} ,
1616 RuntimeEvent , RuntimeEventKind ,
1717} ;
1818
1919const HTTP_HEAD_LIMIT : usize = 64 * 1024 ;
2020
21- pub ( crate ) struct HttpHeadResponse {
22- pub ( crate ) status_code : u16 ,
21+ pub ( crate ) struct ProbeResponse {
22+ pub ( crate ) status_code : Option < u16 > ,
2323 pub ( crate ) bytes : usize ,
2424}
2525
26- pub ( crate ) fn execute (
26+ pub ( crate ) fn execute_with_protocol (
2727 ebus : & EventBus ,
2828 outbound : & NetworkNode ,
2929 target : & ProbeTarget ,
3030 stream : ProxiedTcpStream ,
31- ) -> Result < HttpHeadResponse , String > {
31+ protocol : ProbeProtocol ,
32+ ) -> Result < ProbeResponse , String > {
3233 let mut tls = observe_stage ( ebus, outbound, "tls-handshake" , || {
3334 tls_handshake (
34- ObservedProbeStream :: new ( stream, ebus. clone ( ) , outbound, "https-head" ) ,
35+ ObservedProbeStream :: new ( stream, ebus. clone ( ) , outbound, protocol . as_str ( ) ) ,
3536 & target. host ,
3637 )
3738 } ) ?;
39+ if protocol == ProbeProtocol :: TlsHandshake {
40+ return Ok ( ProbeResponse {
41+ status_code : None ,
42+ bytes : 0 ,
43+ } ) ;
44+ }
3845 observe_stage ( ebus, outbound, "http-head-write" , || {
3946 let request = http_head_request ( target) ;
4047 tls. write_all ( & request)
@@ -131,7 +138,7 @@ fn http_head_request(target: &ProbeTarget) -> Vec<u8> {
131138
132139fn read_http_head (
133140 tls : & mut StreamOwned < ClientConnection , ObservedProbeStream > ,
134- ) -> Result < HttpHeadResponse , String > {
141+ ) -> Result < ProbeResponse , String > {
135142 let mut response = Vec :: new ( ) ;
136143 let mut buffer = [ 0_u8 ; 4096 ] ;
137144 loop {
@@ -166,8 +173,8 @@ fn read_http_head(
166173 . ok_or_else ( || format ! ( "HTTPS HEAD status line has no code: `{status_line}`" ) ) ?
167174 . parse :: < u16 > ( )
168175 . map_err ( |error| format ! ( "invalid HTTPS HEAD status line `{status_line}`: {error}" ) ) ?;
169- Ok ( HttpHeadResponse {
170- status_code,
176+ Ok ( ProbeResponse {
177+ status_code : Some ( status_code ) ,
171178 bytes : response. len ( ) ,
172179 } )
173180}
0 commit comments