1+ // Copyright 2026-Present Datadog, Inc. https://www.datadoghq.com/
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ #![ cfg( windows) ]
5+
6+ use libdd_http_client:: { HttpClient , HttpMethod , HttpRequest } ;
7+ use std:: time:: Duration ;
8+ use tokio:: io:: { AsyncReadExt , AsyncWriteExt } ;
9+ use tokio:: net:: windows:: named_pipe:: ServerOptions ;
10+
11+ #[ cfg_attr( miri, ignore) ]
12+ #[ tokio:: test]
13+ async fn test_named_pipe_round_trip ( ) {
14+ let pipe_name = format ! (
15+ r"\\.\pipe\dd_http_client_test_{}_{}" ,
16+ std:: process:: id( ) ,
17+ fastrand:: u64 ( ..)
18+ ) ;
19+
20+ let server = ServerOptions :: new ( )
21+ . first_pipe_instance ( true )
22+ . create ( & pipe_name)
23+ . unwrap ( ) ;
24+
25+ let pipe_name_clone = pipe_name. clone ( ) ;
26+ tokio:: spawn ( async move {
27+ server. connect ( ) . await . unwrap ( ) ;
28+ let mut buf = vec ! [ 0u8 ; 1024 ] ;
29+ let _ = server. read ( & mut buf) . await . unwrap ( ) ;
30+ server
31+ . write_all ( b"HTTP/1.1 200 OK\r \n Content-Length: 2\r \n \r \n ok" )
32+ . await
33+ . unwrap ( ) ;
34+ } ) ;
35+
36+ let client = HttpClient :: builder ( )
37+ . base_url ( "http://localhost" . to_owned ( ) )
38+ . timeout ( Duration :: from_secs ( 5 ) )
39+ . windows_named_pipe ( & pipe_name_clone)
40+ . build ( )
41+ . unwrap ( ) ;
42+
43+ let req = HttpRequest :: new ( HttpMethod :: Get , "http://localhost/ping" . to_owned ( ) ) ;
44+ let response = client. send ( req) . await . unwrap ( ) ;
45+
46+ assert_eq ! ( response. status_code, 200 ) ;
47+ assert_eq ! ( response. body. as_ref( ) , b"ok" ) ;
48+ }
49+
50+ #[ test]
51+ fn test_named_pipe_client_constructs ( ) {
52+ let client = HttpClient :: builder ( )
53+ . base_url ( "http://localhost" . to_owned ( ) )
54+ . timeout ( Duration :: from_secs ( 5 ) )
55+ . windows_named_pipe ( r"\\.\pipe\dd_test_construct" )
56+ . build ( ) ;
57+ assert ! ( client. is_ok( ) ) ;
58+ }
0 commit comments