(self, path, extra_headers=None)
| 323 | |
| 324 | # Render a file from media with iframe site wrapper |
| 325 | def actionWrapper(self, path, extra_headers=None): |
| 326 | if not extra_headers: |
| 327 | extra_headers = {} |
| 328 | script_nonce = self.getScriptNonce() |
| 329 | |
| 330 | match = re.match(r"/(?P<address>[A-Za-z0-9\._-]+)(?P<inner_path>/.*|$)", path) |
| 331 | just_added = False |
| 332 | if match: |
| 333 | address = match.group("address") |
| 334 | inner_path = match.group("inner_path").lstrip("/") |
| 335 | |
| 336 | if not inner_path or path.endswith("/"): # It's a directory |
| 337 | content_type = self.getContentType("index.html") |
| 338 | else: # It's a file |
| 339 | content_type = self.getContentType(inner_path) |
| 340 | |
| 341 | is_html_file = "html" in content_type or "xhtml" in content_type |
| 342 | |
| 343 | if not is_html_file: |
| 344 | return self.actionSiteMedia("/media" + path) # Serve non-html files without wrapper |
| 345 | |
| 346 | if self.isAjaxRequest(): |
| 347 | return self.error403("Ajax request not allowed to load wrapper") # No ajax allowed on wrapper |
| 348 | |
| 349 | if self.isWebSocketRequest(): |
| 350 | return self.error403("WebSocket request not allowed to load wrapper") # No websocket |
| 351 | |
| 352 | if "text/html" not in self.env.get("HTTP_ACCEPT", ""): |
| 353 | return self.error403("Invalid Accept header to load wrapper") |
| 354 | if "prefetch" in self.env.get("HTTP_X_MOZ", "") or "prefetch" in self.env.get("HTTP_PURPOSE", ""): |
| 355 | return self.error403("Prefetch not allowed to load wrapper") |
| 356 | |
| 357 | site = SiteManager.site_manager.get(address) |
| 358 | |
| 359 | if site and site.content_manager.contents.get("content.json"): |
| 360 | title = site.content_manager.contents["content.json"]["title"] |
| 361 | else: |
| 362 | title = "Loading %s..." % address |
| 363 | site = SiteManager.site_manager.get(address) |
| 364 | if site: # Already added, but not downloaded |
| 365 | if time.time() - site.announcer.time_last_announce > 5: |
| 366 | site.log.debug("Reannouncing site...") |
| 367 | gevent.spawn(site.update, announce=True) |
| 368 | else: # If not added yet |
| 369 | site = SiteManager.site_manager.need(address) |
| 370 | just_added = True |
| 371 | |
| 372 | if not site: |
| 373 | return False |
| 374 | |
| 375 | self.sendHeader(extra_headers=extra_headers, script_nonce=script_nonce) |
| 376 | |
| 377 | min_last_announce = (time.time() - site.announcer.time_last_announce) / 60 |
| 378 | if min_last_announce > 60 and site.isServing() and not just_added: |
| 379 | site.log.debug("Site requested, but not announced recently (last %.0fmin ago). Updating..." % min_last_announce) |
| 380 | gevent.spawn(site.update, announce=True) |
| 381 | |
| 382 | return iter([self.renderWrapper(site, path, inner_path, title, extra_headers, script_nonce=script_nonce)]) |
no test coverage detected