MCPcopy Create free account
hub / github.com/0x676e67/wreq-python / update

Method update

src/client/async_impl/mod.rs:458–531  ·  view source on GitHub ↗
(&self, py: Python, mut kwds: Option<UpdateClientParams>)

Source from the content-addressed store, hash-verified

456 /// Updates the client with the given parameters.
457 #[pyo3(signature = (**kwds))]
458 pub fn update(&self, py: Python, mut kwds: Option<UpdateClientParams>) -> PyResult<()> {
459 py.allow_threads(|| {
460 let params = kwds.get_or_insert_default();
461
462 // Create a new client with the current configuration.
463 let mut update = self.0.update();
464
465 // Impersonation options.
466 apply_option!(apply_if_some_inner, update, params.impersonate, emulation);
467
468 // Updated headers options.
469 if let Some(src) = params.headers.take() {
470 update = update.headers(|dst| {
471 // IntoIter of HeaderMap yields (Option<HeaderName>, HeaderValue).
472 // The first time a name is yielded, it will be Some(name), and if
473 // there are more values with the same name, the next yield will be
474 // None.
475
476 let mut prev_entry: Option<OccupiedEntry<_>> = None;
477 for (key, value) in src.0 {
478 match key {
479 Some(key) => match dst.entry(key) {
480 Entry::Occupied(mut e) => {
481 e.insert(value);
482 prev_entry = Some(e);
483 }
484 Entry::Vacant(e) => {
485 let e = e.insert_entry(value);
486 prev_entry = Some(e);
487 }
488 },
489 None => match prev_entry {
490 Some(ref mut entry) => {
491 entry.append(value);
492 }
493 None => unreachable!("HeaderMap::into_iter yielded None first"),
494 },
495 }
496 }
497 });
498 }
499
500 // Headers order options.
501 apply_option!(
502 apply_if_some_inner,
503 update,
504 params.headers_order,
505 headers_order
506 );
507
508 // Network options.
509 apply_option!(apply_if_some_inner, update, params.proxies, proxies);
510 apply_option!(
511 apply_if_some_inner,
512 update,
513 params.local_address,
514 local_address
515 );

Callers 3

test_badsslFunction · 0.95
test_update_headersFunction · 0.95
test_update_impersonateFunction · 0.95

Calls 3

insertMethod · 0.80
appendMethod · 0.80
headersMethod · 0.45

Tested by 3

test_badsslFunction · 0.76
test_update_headersFunction · 0.76
test_update_impersonateFunction · 0.76