MCPcopy Create free account
hub / github.com/apify/impit / cookies

Method cookies

impit-python/src/cookies.rs:105–175  ·  view source on GitHub ↗
(&self, url: &Url)

Source from the content-addressed store, hash-verified

103 }
104
105 fn cookies(&self, url: &Url) -> Option<reqwest::header::HeaderValue> {
106 Python::attach(|py| {
107 let cookie_list = PyIterator::from_object(&self.cookie_jar.bind_borrowed(py)).unwrap();
108
109 cookie_list
110 .filter_map(|py_cookie| {
111 let py_cookie = py_cookie.unwrap();
112
113 let domain = py_cookie
114 .getattr("domain")
115 .and_then(|attr| attr.extract::<String>())
116 .unwrap_or_default();
117 let path = py_cookie
118 .getattr("path")
119 .and_then(|attr| attr.extract::<String>())
120 .unwrap_or_default();
121 let secure = py_cookie
122 .getattr("secure")
123 .and_then(|attr| attr.extract::<bool>())
124 .unwrap_or_default();
125
126 if !domain.is_empty() && !url.host_str().unwrap_or_default().contains(&domain) {
127 return None;
128 }
129 if !url.path().starts_with(&path) {
130 return None;
131 }
132 if secure && !url.scheme().eq("https") {
133 return None;
134 }
135 let is_expired = py_cookie
136 .getattr("is_expired")
137 .unwrap()
138 .call(
139 (),
140 [(
141 "now",
142 SystemTime::now()
143 .duration_since(UNIX_EPOCH)
144 .ok()
145 .map(|now| now.as_secs()),
146 )]
147 .into_py_dict(py)
148 .ok()
149 .as_ref(),
150 )
151 .unwrap();
152
153 if is_expired.is_truthy().unwrap() {
154 None
155 } else {
156 let name = py_cookie
157 .getattr("name")
158 .unwrap()
159 .extract::<String>()
160 .unwrap();
161 let value = py_cookie
162 .getattr("value")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected