Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sdk/core/azure-core/azure/core/pipeline/policies/redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def increment(self, settings, response, redirect_location):
response.http_request.method = 'GET'
for non_redirect_header in self._remove_headers_on_redirect:
response.http_request.headers.pop(non_redirect_header, None)
return settings['redirects'] > 0 or not settings['allow']
return settings['redirects'] > 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move the check out of increment method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two reasons:

  1. The check for settings['allow'] is not getting executed here. When it is configured with no_redirects the 'redirects' in the settings still defaults to 30 attempts. So it will continue to make redirect attempts before evaluating if redirects are allowed.
  2. If 'allow' is checked in the increment method and is False, the method will return False which raises a TooManyRedirectsError in the send method instead of returning the response.


def send(self, request):
"""Sends the PipelineRequest object to the next policy.
Expand All @@ -158,7 +158,7 @@ def send(self, request):
while retryable:
response = self.next.send(request)
redirect_location = self.get_redirect_location(response)
if redirect_location:
if redirect_location and redirect_settings['allow']:
retryable = self.increment(redirect_settings, response, redirect_location)
request.http_request = response.http_request
continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def send(self, request):
while redirects_remaining:
response = await self.next.send(request)
redirect_location = self.get_redirect_location(response)
if redirect_location:
if redirect_location and redirect_settings['allow']:
redirects_remaining = self.increment(redirect_settings, response, redirect_location)
request.http_request = response.http_request
continue
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/examples/examples_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def test_example_async_redirect_policy():

# It can also be overridden per operation.
async with AsyncPipelineClient(base_url=url, config=config) as client:
response = await client._pipeline.run(request, redirect_max=5)
response = await client._pipeline.run(request, permit_redirects=True, redirect_max=5)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permit_redirects=True is the default value, not right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is default value. The reason I used it here is because a couple lines up I disable redirects and then wanted to re-enable it for the test example. I'll move it to a separate test.


# [END async_redirect_policy]

Expand Down
2 changes: 1 addition & 1 deletion sdk/core/azure-core/examples/examples_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_example_redirect_policy():
# It can also be overridden per operation.
client = PipelineClient(base_url=url, config=config)
request = client.get(url)
pipeline_response = client._pipeline.run(request, redirect_max=5)
pipeline_response = client._pipeline.run(request, permit_redirects=True, redirect_max=5)
# [END redirect_policy]

response = pipeline_response.http_response
Expand Down