This fairly complex and heuristic function refreshes a server response for replay. - It adjusts date, expires, and last-modified headers. - It adjusts cookie expiration.
(self, now=None)
| 1172 | self._set_cookies(value) |
| 1173 | |
| 1174 | def refresh(self, now=None): |
| 1175 | """ |
| 1176 | This fairly complex and heuristic function refreshes a server |
| 1177 | response for replay. |
| 1178 | |
| 1179 | - It adjusts date, expires, and last-modified headers. |
| 1180 | - It adjusts cookie expiration. |
| 1181 | """ |
| 1182 | if not now: |
| 1183 | now = time.time() |
| 1184 | delta = now - self.timestamp_start |
| 1185 | refresh_headers = [ |
| 1186 | "date", |
| 1187 | "expires", |
| 1188 | "last-modified", |
| 1189 | ] |
| 1190 | for i in refresh_headers: |
| 1191 | if i in self.headers: |
| 1192 | d = parsedate_tz(self.headers[i]) |
| 1193 | if d: |
| 1194 | new = mktime_tz(d) + delta |
| 1195 | try: |
| 1196 | self.headers[i] = formatdate(new, usegmt=True) |
| 1197 | except OSError: # pragma: no cover |
| 1198 | pass # value out of bounds on Windows only (which is why we exclude it from coverage). |
| 1199 | c = [] |
| 1200 | for set_cookie_header in self.headers.get_all("set-cookie"): |
| 1201 | try: |
| 1202 | refreshed = cookies.refresh_set_cookie_header(set_cookie_header, delta) |
| 1203 | except ValueError: |
| 1204 | refreshed = set_cookie_header |
| 1205 | c.append(refreshed) |
| 1206 | if c: |
| 1207 | self.headers.set_all("set-cookie", c) |
| 1208 | |
| 1209 | |
| 1210 | class HTTPFlow(flow.Flow): |