Skip to content
Myr

Merge pull request #4983 from jaketreacher/2949-trusted-domain

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add trusted domains

authored by Kenneth Reitz · committed by GitHub · parents bbc3d43, fbe48fb · Browse files · 1 file+8 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−1 removed

  • other:+8 added−1 removed

1 file+8 added−1 removed

modified:requests/sessions.py+8 added-1 removed
93 unmodified lines
949596class SessionRedirectMixin(object):9798 def __init__(self):99 #: A list of domains that will be excluded from auth stripping100 self.trusted_domains = []101102 def get_redirect_target(self, resp):103 """Receives a Response. Returns a redirect URI or ``None``"""104 # Due to the nature of how requests processes redirects this method will105 # be called at least once upon the original response and at least twice
17 unmodified lines
123 def should_strip_auth(self, old_url, new_url):124 """Decide whether Authorization header should be removed when redirecting"""125 old_parsed = urlparse(old_url)126 new_parsed = urlparse(new_url)123 if old_parsed.hostname != new_parsed.hostname:127 if (old_parsed.hostname != new_parsed.hostname128 and new_parsed.hostname not in self.trusted_domains):129 return True130 # Special case: allow http -> https redirect when using the standard131 # ports. This isn't specified by RFC 7235, but is kept to avoid132 # breaking backwards compatibility with older versions of requests
285 unmodified lines
418 self.adapters = OrderedDict()419 self.mount('https://', HTTPAdapter())420 self.mount('http://', HTTPAdapter())421422 super().__init__()423424 def __enter__(self):425 return self426427 def __exit__(self, *args):
347 unmodified lines