Skip to content
Myr

Issue #2334 - HTTPDigestAuth - Improved per-thread state init

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

Inspired in @tardyp approach.

authored by exvito · committed by exvito · parent 142e24d · Browse files · 1 file+10 added−12 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+10 added−12 removed

  • other:+10 added−12 removed

1 file+10 added−12 removed

modified:requests/auth.py+10 added-12 removed
64 unmodified lines
65 self.username = username66 self.password = password67 # Keep state in per-thread local storage68 self.tl = threading.local()69 self.init_per_thread_state()6970 def init_per_thread_state(self):71 # Ensure state is initialized just once per-thread72 if not hasattr(self.tl, 'init'):73 self.tl.init = True72 self.tl.last_nonce = ''73 self.tl.nonce_count = 074 self.tl.chal = {}75 self.tl.pos = None76 self.tl.num_401_calls = None74 self.tl.last_nonce = ''75 self.tl.nonce_count = 076 self.tl.chal = {}77 self.tl.pos = None78 self.tl.num_401_calls = None7980 def build_digest_header(self, method, url):8182 realm = self.tl.chal['realm']
119 unmodified lines
202 self.tl.num_401_calls = 1203 return r204205 def __call__(self, r):204 # When called from a thread other than the one that __init__'ed us205 # per-thread state may be missing: initialize it if that's the case.206 try:207 self.tl.last_nonce208 except AttributeError:209 self.init_per_thread_state()206 # Initialize per-thread state, if needed207 self.init_per_thread_state()208 # If we have a saved nonce, skip the 401209 if self.tl.last_nonce:210 r.headers['Authorization'] = self.build_digest_header(r.method, r.url)211 try:
12 unmodified lines