Skip to content

Commit

Permalink
- Make CurlClient fail fast
Browse files Browse the repository at this point in the history
- Fix CurlClient file dependent features for the case of several instances
  • Loading branch information
voodam committed Jul 11, 2023
1 parent 0afb267 commit 782d55e
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions framework/curl_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def requests(self, value):
@property
def responses(self) -> List[CurlResponse]:
"""List of all received responses."""
if not self.dump_headers:
raise ValueError(
"'dump_headers' argument must be enabled for using 'responses' property"
)
return list(self._responses)

@property
Expand All @@ -165,6 +169,10 @@ def statuses(self) -> Dict[int, int]:
"""Received statuses counters, like:
{200: 1, 400: 2}
"""
if not self.dump_headers:
raise ValueError(
"'dump_headers' argument must be enabled for using 'statuses' property"
)
return dict(self._statuses)

@statuses.setter
Expand All @@ -180,7 +188,7 @@ def last_stats(self) -> Dict[str, Any]:
return (self._stats or [None])[-1]

@property
def stats(self) -> List[Dict[int, int]]:
def stats(self) -> List[Dict[str, Any]]:
"""List of stats of all transfers"""
return list(self._stats)

Expand All @@ -193,17 +201,20 @@ def binary_version(self) -> Optional[str]:
@property
def cookie_jar_path(self):
"""Path to save/load cookies."""
return Path(self.workdir) / "curl-default.jar"
# fix for the case of several client instances
return Path(self.workdir) / f"curl-{id(self)}.jar"

@property
def output_path(self):
"""Path to write stdout (response)."""
return Path(self.workdir) / "curl-output"
# fix for the case of several client instances
return Path(self.workdir) / f"curl-output-{id(self)}"

@property
def headers_dump_path(self):
"""Path do dump received headers."""
return Path(self.workdir) / "curl-default.hdr"
# fix for the case of several client instances
return Path(self.workdir) / f"curl-{id(self)}.hdr"

@property
def cookie_string(self) -> str:
Expand All @@ -222,6 +233,10 @@ def clear_stats(self):
self._stats = []

def form_command(self):
if self.parallel and self.dump_headers:
# TODO #488
raise ValueError("--parallel and --dump-header don't work together properly")

options = ["--no-progress-meter", "--create-dirs"]

if self.dump_headers:
Expand Down Expand Up @@ -264,7 +279,6 @@ def form_command(self):
def parse_out(self, stdout, stderr):
if self.dump_headers:
for dump in filter(None, self._read_headers_dump().split(b"\r\n\r\n")):

response = CurlResponse(
headers_dump=dump,
stdout_raw=self._read_output() if not self.disable_output else b"",
Expand Down

0 comments on commit 782d55e

Please sign in to comment.