Function request

Source
pub async fn request(http_req: HttpRequest) -> HttpStat
Expand description

Performs an HTTP request and returns detailed statistics about the request lifecycle.

This function handles HTTP/1.1, HTTP/2, and HTTP/3 requests with the following features:

  • Automatic protocol selection based on ALPN negotiation
  • DNS resolution with support for custom IP mappings
  • TLS handshake with certificate verification
  • Response body handling with optional file output
  • Detailed timing statistics for each phase of the request

§Arguments

  • http_req - An HttpRequest struct containing the request configuration including:
    • URI and HTTP method
    • ALPN protocols to negotiate
    • Custom DNS resolutions
    • Headers and request body
    • TLS verification settings
    • Output file path (optional)

§Returns

Returns an HttpStat struct containing:

  • DNS lookup time
  • QUIC connection time
  • TCP connection time
  • TLS handshake time (for HTTPS)
  • Server processing time
  • Content transfer time
  • Total request time
  • Response status and headers
  • Response body (if not written to file)
  • TLS and certificate information (for HTTPS)
  • Any errors that occurred during the request
Examples found in repository?
examples/client.rs (line 5)
4async fn main() {
5    let stat = request("https://www.baidu.com/".try_into().unwrap()).await;
6    // println!("{:?}", stat);
7    println!("{stat}");
8}