Skip to content

Commit

Permalink
fix: handle server-timing headers with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytelife26 committed Oct 29, 2024
1 parent bee9297 commit 89aa415
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cfspeedtest/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import logging
import re
import statistics
import time
from enum import Enum
Expand All @@ -16,6 +17,8 @@

log = logging.getLogger("cfspeedtest")

TIMING_DURATION_RE = re.compile(r"dur=([0-9.]+)")


class TestType(Enum):
"""The type of an individual test."""
Expand Down Expand Up @@ -191,9 +194,8 @@ def run_test(self, test: TestSpec) -> TestTimers:
test.type.value, url, data=data, timeout=self.timeout
)
coll.full.append(time.time() - start)
coll.server.append(
float(r.headers["Server-Timing"].split("=")[1].split(",")[0]) / 1e3
)
timing_match = TIMING_DURATION_RE.search(r.headers["Server-Timing"])
coll.server.append(float(timing_match.group(1)) / 1e3)
coll.request.append(
r.elapsed.seconds + r.elapsed.microseconds / 1e6
)
Expand Down

0 comments on commit 89aa415

Please sign in to comment.