|
5 | 5 | from __future__ import absolute_import
|
6 | 6 | import os
|
7 | 7 | import gc
|
| 8 | +import re |
8 | 9 | import time
|
9 | 10 | import json
|
10 | 11 | import types
|
|
16 | 17 | from twisted.internet import reactor, defer
|
17 | 18 | from twisted.python import log
|
18 | 19 | import six
|
| 20 | +from PyQt5.QtWebKit import QWebSettings |
19 | 21 |
|
20 | 22 | import splash
|
21 | 23 | from splash.qtrender import (
|
@@ -347,6 +349,36 @@ def render_POST(self, request):
|
347 | 349 | }).encode('utf-8')
|
348 | 350 |
|
349 | 351 |
|
| 352 | +class CacheControlResource(Resource): |
| 353 | + isLeaf = True |
| 354 | + content_type = "application/json" |
| 355 | + |
| 356 | + def render_POST(self, request): |
| 357 | + for key, pattern in ( |
| 358 | + ('max_pages', r'^\d+$'), |
| 359 | + ('object_capacities', r'^\d+,\d+,\d+$'), |
| 360 | + ): |
| 361 | + if request.args.get(key): |
| 362 | + data = ''.join(request.args[key]) |
| 363 | + if not re.match(pattern, data): |
| 364 | + request.setResponseCode(400) |
| 365 | + return json.dumps({ |
| 366 | + 'status': 'error', |
| 367 | + 'key': key, |
| 368 | + 'supported_format': pattern, |
| 369 | + 'received': data, |
| 370 | + }) |
| 371 | + if request.args.get('max_pages'): |
| 372 | + data = ''.join(request.args['max_pages']) |
| 373 | + QWebSettings.setMaximumPagesInCache(int(data)) |
| 374 | + if request.args.get('object_capacities'): |
| 375 | + data = ''.join(request.args['object_capacities']).split(',') |
| 376 | + QWebSettings.setObjectCacheCapacities(*[int(x) for x in data]) |
| 377 | + return json.dumps({ |
| 378 | + "status": "ok", |
| 379 | + }).encode('utf-8') |
| 380 | + |
| 381 | + |
350 | 382 | BOOTSTRAP_THEME = 'simplex'
|
351 | 383 | CODEMIRROR_OPTIONS = """{
|
352 | 384 | mode: 'lua',
|
@@ -704,6 +736,7 @@ def __init__(self, pool, ui_enabled, lua_enabled, lua_sandbox_enabled,
|
704 | 736 |
|
705 | 737 | self.putChild(b"_debug", DebugResource(pool))
|
706 | 738 | self.putChild(b"_gc", ClearCachesResource())
|
| 739 | + self.putChild(b"_cache_control", CacheControlResource()) |
707 | 740 |
|
708 | 741 | # backwards compatibility
|
709 | 742 | self.putChild(b"debug", DebugResource(pool, warn=True))
|
|
0 commit comments