diff --git a/dist/ttfb-go b/dist/ttfb-go index 02871b0..05ed0bc 100755 Binary files a/dist/ttfb-go and b/dist/ttfb-go differ diff --git a/dist/ttfb-go_darwin_amd64 b/dist/ttfb-go_darwin_amd64 index 40010fc..e591b19 100755 Binary files a/dist/ttfb-go_darwin_amd64 and b/dist/ttfb-go_darwin_amd64 differ diff --git a/dist/ttfb-go_darwin_arm64 b/dist/ttfb-go_darwin_arm64 index be2f1f5..54a852a 100755 Binary files a/dist/ttfb-go_darwin_arm64 and b/dist/ttfb-go_darwin_arm64 differ diff --git a/dist/ttfb-go_linux_arm b/dist/ttfb-go_linux_arm index 01416ca..f8ed2e5 100755 Binary files a/dist/ttfb-go_linux_arm and b/dist/ttfb-go_linux_arm differ diff --git a/dist/ttfb-go_linux_arm64 b/dist/ttfb-go_linux_arm64 index 2038048..94efc8b 100755 Binary files a/dist/ttfb-go_linux_arm64 and b/dist/ttfb-go_linux_arm64 differ diff --git a/dist/ttfb-go_linux_arm64_static b/dist/ttfb-go_linux_arm64_static index 4c39f3c..1301853 100755 Binary files a/dist/ttfb-go_linux_arm64_static and b/dist/ttfb-go_linux_arm64_static differ diff --git a/dist/ttfb-go_linux_arm_static b/dist/ttfb-go_linux_arm_static index bc642d1..5d015b1 100755 Binary files a/dist/ttfb-go_linux_arm_static and b/dist/ttfb-go_linux_arm_static differ diff --git a/dist/ttfb-go_static b/dist/ttfb-go_static index c2eac76..7af0bae 100755 Binary files a/dist/ttfb-go_static and b/dist/ttfb-go_static differ diff --git a/main.go b/main.go index e902ee6..52519e5 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( ) // MeasureTTFB measures the Time to First Byte for the given URL. -func MeasureTTFB(url string, cookie string) (int64, int, error) { +func MeasureTTFB(url string, cookies []string) (int64, int, error) { // Create a custom HTTP transport to allow measuring the TTFB. transport := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, @@ -28,14 +28,14 @@ func MeasureTTFB(url string, cookie string) (int64, int, error) { return 0, 0, err } - // If a cookie is provided, set it in the request header. - if cookie != "" { - // Clean up and format the cookie properly - cookie = strings.TrimSpace(cookie) - if !strings.Contains(cookie, "=") { - return 0, 0, fmt.Errorf("invalid cookie format") + // If cookies are provided, set them in the request header. + if len(cookies) > 0 { + for _, cookie := range cookies { + if !strings.Contains(cookie, "=") { + return 0, 0, fmt.Errorf("invalid cookie format") + } + req.Header.Add("Cookie", strings.TrimSpace(cookie)) } - req.Header.Set("Cookie", cookie) } // Record the start time. @@ -56,7 +56,7 @@ func MeasureTTFB(url string, cookie string) (int64, int, error) { func main() { // Define and parse command-line flags. - cookieFile := flag.String("c", "", "Path to file containing the authentication cookie") + cookieFile := flag.String("c", "", "Path to file containing the authentication cookies") flag.Parse() // Check if the URL is provided as an argument. @@ -67,19 +67,19 @@ func main() { url := flag.Arg(0) - // Read the cookie from the specified file if provided. - var cookie string + // Read the cookies from the specified file if provided. + var cookies []string if *cookieFile != "" { data, err := ioutil.ReadFile(*cookieFile) if err != nil { fmt.Printf("Error reading cookie file: %v\n", err) os.Exit(1) } - cookie = strings.TrimSpace(string(data)) + cookies = strings.Split(strings.TrimSpace(string(data)), ";") } // Measure the TTFB. - ttfb, statusCode, err := MeasureTTFB(url, cookie) + ttfb, statusCode, err := MeasureTTFB(url, cookies) if err != nil { fmt.Printf("Error measuring TTFB: %v\n", err) os.Exit(1)