Closed itamarzil123 closed 11 months ago
read_to_end reads until the connection closes. You need to parse the response to determine when it is complete.
@sfackler thank you for your answer. as I mentioned the code I shosed is a simplified part. the rest of the code includes: let response_str = String::from_utf8_lossy(&response); println!("response_str: {}", response_str); and also writing to files. the operation is successfull, however it takes 10 minutes to complete (unlike using curl / browser which takes 2 seconds) I tried buffering and didn't work. another thing I noticed - looking at the Wireshark logs: when I do: curl, I see no Encrypted Alert, the handshake and the application data all working great, but in my Rust program when I send the https request using native-tls I see that the read operation takes long and also I see: "Encrypted Alert" Content Type: Alert 21 in wireshark after those 10+- minutes and then the response is successful any thoughts ? or even how to debug ?
I will also add that with Rustls library there were no issues (maybe related to the fact TLS 1.3 is used ?) anyway I prefer the API of native-tls so I hope I will resolve it
Again, you cannot just read until the socket closes to get a complete HTTP response: https://en.wikipedia.org/wiki/HTTP_persistent_connection
I am using native_tls::{TlsConnector, TlsStream} as part of building a browser project in Rust.
reader.read_to_end(...) -
this read operation hangs for about 10 minutes - and only after this enormous delay, the html contents of the URL (www.bbc.com for example) is resolved. for comparison - in browsers like chrome - takes 2 seconds for www.bbc.com, in curl takes 2-5 seconds. any thoughts on why this process my take so long ? (nothing serious on the wireshark logs, handshake times seems reasonable) simplified version of my code: