#web-performance #performance #timing #http #http-status #web #http-response

http-timings

A simple library to measure the key HTTP timings from the development tools

5 releases

0.2.0 Jan 21, 2025
0.1.4 Oct 25, 2024
0.1.3 Aug 24, 2024
0.1.2 Apr 15, 2024

#1658 in Web programming

Download history 91/week @ 2024-10-20 25/week @ 2024-10-27 5/week @ 2024-11-03 1/week @ 2024-11-10 1/week @ 2024-11-17 22/week @ 2024-12-08 101/week @ 2025-01-19 3/week @ 2025-01-26 5/week @ 2025-02-02

109 downloads per month

Custom license

22KB
436 lines

http-timings: A library to measure HTTP timings

Inspired by the libraries TTFB by phip1611 and ssl-expiration by onur. This library provides the following information from any given URL:

  • Status code
  • Body of the response
  • SSL Certificate information
  • DNS Lookup Time
  • TCP Connection Time
  • TLS Handshake Time
  • HTTP Send Time
  • Time to First Byte
  • Content Download Time

Usage

use http_timings::from_string;

let url = "https://www.example.com";
let timeout = Some(Duration::from_secs(5)); // Set a timeout of 5 seconds
match from_string(url, timeout) {
    Ok(response) => {
        println!("Response Status: {}", response.status);
        println!("Response Body: {}", response.body);
        if let Some(cert_info) = response.certificate_information {
            println!("Certificate Subject: {:?}", cert_info.subject);
            println!("Certificate Issued At: {:?}", cert_info.issued_at);
            println!("Certificate Expires At: {:?}", cert_info.expires_at);
            println!("Is Certificate Active: {:?}", cert_info.is_active);
        } else {
            println!("No certificate information available.");
        }
    },
    Err(e) => {
        eprintln!("Error occurred: {:?}", e);
    }
}

The Response struct provides all the information about the request. The timings in both relative and total terms. The relative timings are the time taken for each step of the request, while the total timings are the time taken from the start of the request to the end of the request.

The URL input can be any valid website as well as any valid IP.

Dependencies

~12MB
~369K SLoC