Fixup
This commit is contained in:
parent
26522adf6e
commit
da62d3ed44
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26
main.go
26
main.go
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// MeasureTTFB measures the Time to First Byte for the given URL.
|
// 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.
|
// Create a custom HTTP transport to allow measuring the TTFB.
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
@ -28,14 +28,14 @@ func MeasureTTFB(url string, cookie string) (int64, int, error) {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a cookie is provided, set it in the request header.
|
// If cookies are provided, set them in the request header.
|
||||||
if cookie != "" {
|
if len(cookies) > 0 {
|
||||||
// Clean up and format the cookie properly
|
for _, cookie := range cookies {
|
||||||
cookie = strings.TrimSpace(cookie)
|
if !strings.Contains(cookie, "=") {
|
||||||
if !strings.Contains(cookie, "=") {
|
return 0, 0, fmt.Errorf("invalid cookie format")
|
||||||
return 0, 0, fmt.Errorf("invalid cookie format")
|
}
|
||||||
|
req.Header.Add("Cookie", strings.TrimSpace(cookie))
|
||||||
}
|
}
|
||||||
req.Header.Set("Cookie", cookie)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the start time.
|
// Record the start time.
|
||||||
|
@ -56,7 +56,7 @@ func MeasureTTFB(url string, cookie string) (int64, int, error) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Define and parse command-line flags.
|
// 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()
|
flag.Parse()
|
||||||
|
|
||||||
// Check if the URL is provided as an argument.
|
// Check if the URL is provided as an argument.
|
||||||
|
@ -67,19 +67,19 @@ func main() {
|
||||||
|
|
||||||
url := flag.Arg(0)
|
url := flag.Arg(0)
|
||||||
|
|
||||||
// Read the cookie from the specified file if provided.
|
// Read the cookies from the specified file if provided.
|
||||||
var cookie string
|
var cookies []string
|
||||||
if *cookieFile != "" {
|
if *cookieFile != "" {
|
||||||
data, err := ioutil.ReadFile(*cookieFile)
|
data, err := ioutil.ReadFile(*cookieFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error reading cookie file: %v\n", err)
|
fmt.Printf("Error reading cookie file: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
cookie = strings.TrimSpace(string(data))
|
cookies = strings.Split(strings.TrimSpace(string(data)), ";")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Measure the TTFB.
|
// Measure the TTFB.
|
||||||
ttfb, statusCode, err := MeasureTTFB(url, cookie)
|
ttfb, statusCode, err := MeasureTTFB(url, cookies)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error measuring TTFB: %v\n", err)
|
fmt.Printf("Error measuring TTFB: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
Loading…
Reference in New Issue