Skip to content

Commit e01b86e

Browse files
committed
request headers for no logging works
1 parent de898fa commit e01b86e

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

‎jigsawstack/request.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class RequestConfig(TypedDict):
1313
api_url: str
1414
api_key: str
15-
disable_request_logging: Union[bool, None] = False
15+
headers: Dict[str, str]
1616

1717

1818
# This class wraps the HTTP request creation logic
@@ -34,7 +34,9 @@ def __init__(
3434
self.api_key = config.get("api_key")
3535
self.data = data
3636
self.headers = headers
37-
self.disable_request_logging = config.get("disable_request_logging")
37+
self.disable_request_logging = config.get("headers", {}).get(
38+
"x-jigsaw-no-request-log"
39+
)
3840
self.stream = stream
3941

4042
def perform(self) -> Union[T, None]:
@@ -50,13 +52,16 @@ def perform(self) -> Union[T, None]:
5052
"""
5153
resp = self.make_request(url=f"{self.api_url}{self.path}")
5254

53-
#for binary responses
55+
# for binary responses
5456
if resp.status_code == 200:
5557
content_type = resp.headers.get("content-type", "")
56-
if not resp.text or any(t in content_type for t in ["audio/", "image/", "application/octet-stream", "image/png"]):
58+
if not resp.text or any(
59+
t in content_type
60+
for t in ["audio/", "image/", "application/octet-stream", "image/png"]
61+
):
5762
return cast(T, resp.content)
5863

59-
#for json resposes.
64+
# for json resposes.
6065
if resp.status_code != 200:
6166
try:
6267
error = resp.json()
@@ -94,7 +99,6 @@ def perform_file(self) -> Union[T, None]:
9499
raise_for_code_and_type(
95100
code=500,
96101
message="Failed to parse JigsawStack API response. Please try again.",
97-
error_type="InternalServerError",
98102
)
99103

100104
if resp.status_code != 200:
@@ -105,7 +109,7 @@ def perform_file(self) -> Union[T, None]:
105109
err=error.get("error"),
106110
)
107111

108-
#for binary responses
112+
# for binary responses
109113
if resp.status_code == 200:
110114
content_type = resp.headers.get("content-type", "")
111115
if "application/json" not in content_type:

0 commit comments

Comments
 (0)