Skip to content

Commit db46a25

Browse files
authored
[Test Proxy] Correctly support updates to redirection following setting (#35510)
1 parent 8d26728 commit db46a25

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

tools/azure-sdk-tools/devtools_testutils/sanitizers.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,10 @@ def set_function_recording_options(**kwargs) -> None:
542542
This must be called during test case execution, rather than at a session, module, or class level. To set recording
543543
options for all tests, use `set_session_recording_options` instead.
544544
545-
:keyword bool handle_redirects: The test proxy does not perform transparent follow directs by default. That means
545+
:keyword bool handle_redirects: The test proxy performs transparent follow directs by default. That means
546546
that if the initial request sent through the test proxy results in a 3XX redirect status, the test proxy will
547-
not follow. It will return that redirect response to the client and allow it to handle the redirect. Setting
548-
`handle_redirects` to True will set the proxy to instead handle redirects itself.
547+
follow. Setting `handle_redirects` to False will instead make the test proxy return that redirect response to
548+
the client and allow it to handle the redirect.
549549
:keyword str context_directory: This changes the "root" path that the test proxy uses when loading a recording.
550550
:keyword certificates: A list of `PemCertificate`s. Any number of certificates is allowed.
551551
:type certificates: Iterable[PemCertificate]
@@ -564,10 +564,10 @@ def set_session_recording_options(**kwargs) -> None:
564564
This will set the specified recording options for an entire test session. To set recording options for a single test
565565
-- which is recommended -- use `set_function_recording_options` instead.
566566
567-
:keyword bool handle_redirects: The test proxy does not perform transparent follow directs by default. That means
567+
:keyword bool handle_redirects: The test proxy performs transparent follow directs by default. That means
568568
that if the initial request sent through the test proxy results in a 3XX redirect status, the test proxy will
569-
not follow. It will return that redirect response to the client and allow it to handle the redirect. Setting
570-
`handle_redirects` to True will set the proxy to instead handle redirects itself.
569+
follow. Setting `handle_redirects` to False will instead make the test proxy return that redirect response to
570+
the client and allow it to handle the redirect.
571571
:keyword str context_directory: This changes the "root" path that the test proxy uses when loading a recording.
572572
:keyword certificates: A list of `PemCertificate`s. Any number of certificates is allowed.
573573
:type certificates: Iterable[PemCertificate]
@@ -703,10 +703,11 @@ def _send_recording_options_request(parameters: Dict, headers: Optional[Dict] =
703703
if is_live_and_not_recording():
704704
return
705705

706-
headers_to_send = {}
707-
for key in headers:
708-
if headers[key] is not None:
709-
headers_to_send[key] = headers[key]
706+
headers_to_send = {"Content-Type": "application/json"}
707+
if headers:
708+
for key in headers:
709+
if headers[key] is not None:
710+
headers_to_send[key] = headers[key]
710711

711712
http_client = get_http_client()
712713
http_client.request(
@@ -752,9 +753,10 @@ def _send_sanitizer_request(sanitizer: str, parameters: Dict, headers: Optional[
752753
return
753754

754755
headers_to_send = {"x-abstraction-identifier": sanitizer, "Content-Type": "application/json"}
755-
for key in headers:
756-
if headers[key] is not None:
757-
headers_to_send[key] = headers[key]
756+
if headers:
757+
for key in headers:
758+
if headers[key] is not None:
759+
headers_to_send[key] = headers[key]
758760

759761
http_client = get_http_client()
760762
http_client.request(
@@ -778,9 +780,10 @@ def _send_transform_request(transform: str, parameters: Dict, headers: Optional[
778780
return
779781

780782
headers_to_send = {"x-abstraction-identifier": transform, "Content-Type": "application/json"}
781-
for key in headers:
782-
if headers[key] is not None:
783-
headers_to_send[key] = headers[key]
783+
if headers:
784+
for key in headers:
785+
if headers[key] is not None:
786+
headers_to_send[key] = headers[key]
784787

785788
http_client = get_http_client()
786789
http_client.request(

0 commit comments

Comments
 (0)