1414//! This module exists as a workaround and will hopefully be replaced once reqwest adds
1515//! native support for file output: <https://github.com/seanmonstar/reqwest/issues/2883>
1616
17- #[ cfg( any( unix, windows) ) ]
1817use std:: path:: PathBuf ;
1918
2019/// HTTP 200 OK response with no body
21- #[ cfg( any( unix, windows) ) ]
2220const HTTP_200_RESPONSE : & [ u8 ] = b"HTTP/1.1 200 OK\r \n Content-Length: 0\r \n \r \n " ;
2321
22+ /// Spawns a dump server and configures the ClientBuilder with the appropriate transport
23+ pub ( crate ) fn spawn_dump_server_with_builder (
24+ builder : reqwest:: ClientBuilder ,
25+ output_path : PathBuf ,
26+ ) -> anyhow:: Result < reqwest:: ClientBuilder > {
27+ let server_path = spawn_dump_server ( output_path) ?;
28+
29+ #[ cfg( unix) ]
30+ {
31+ Ok ( builder. unix_socket ( server_path) )
32+ }
33+ #[ cfg( windows) ]
34+ {
35+ Ok ( builder. windows_named_pipe ( server_path. to_string_lossy ( ) . to_string ( ) ) )
36+ }
37+ }
38+
2439/// Async server loop for Unix sockets
2540#[ cfg( unix) ]
2641async fn run_dump_server_unix (
@@ -147,15 +162,13 @@ pub(crate) fn spawn_dump_server(output_path: PathBuf) -> anyhow::Result<PathBuf>
147162}
148163
149164/// Helper function to find a subsequence in a byte slice
150- #[ cfg( any( unix, windows) ) ]
151165fn find_subsequence ( haystack : & [ u8 ] , needle : & [ u8 ] ) -> Option < usize > {
152166 haystack
153167 . windows ( needle. len ( ) )
154168 . position ( |window| window == needle)
155169}
156170
157171/// Parse Content-Length from HTTP headers
158- #[ cfg( any( unix, windows) ) ]
159172fn parse_content_length ( headers_data : & [ u8 ] ) -> Option < usize > {
160173 if let Ok ( headers_str) = std:: str:: from_utf8 ( headers_data) {
161174 for line in headers_str. lines ( ) {
@@ -170,7 +183,6 @@ fn parse_content_length(headers_data: &[u8]) -> Option<usize> {
170183}
171184
172185/// Check if we have received a complete HTTP request
173- #[ cfg( any( unix, windows) ) ]
174186fn is_request_complete (
175187 request_data : & [ u8 ] ,
176188 headers_end_pos : Option < usize > ,
@@ -186,7 +198,6 @@ fn is_request_complete(
186198}
187199
188200/// Read complete HTTP request from an async stream
189- #[ cfg( any( unix, windows) ) ]
190201async fn read_http_request_async < R : tokio:: io:: AsyncReadExt + Unpin > ( stream : & mut R ) -> Vec < u8 > {
191202 let mut request_data = Vec :: new ( ) ;
192203 let mut buffer = [ 0u8 ; 8192 ] ;
@@ -223,7 +234,6 @@ async fn read_http_request_async<R: tokio::io::AsyncReadExt + Unpin>(stream: &mu
223234}
224235
225236/// Write request data to file if non-empty (async version)
226- #[ cfg( any( unix, windows) ) ]
227237async fn write_request_to_file_async ( output_path : & PathBuf , request_data : & [ u8 ] ) {
228238 if !request_data. is_empty ( ) {
229239 if let Err ( e) = tokio:: fs:: write ( output_path, request_data) . await {
@@ -236,7 +246,6 @@ async fn write_request_to_file_async(output_path: &PathBuf, request_data: &[u8])
236246}
237247
238248/// Handle a connection: read HTTP request, write to file, send response
239- #[ cfg( any( unix, windows) ) ]
240249async fn handle_connection_async < S > ( mut stream : S , output_path : PathBuf )
241250where
242251 S : tokio:: io:: AsyncReadExt + tokio:: io:: AsyncWriteExt + Unpin ,
0 commit comments