Skip to content

Commit cb17def

Browse files
committed
no-cache for ajax requests
1 parent 57edb1d commit cb17def

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

code/default/gae_proxy/local/web_control.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def req_log_handler(self):
334334
if not reqs["buffer_size"]:
335335
data = '{"res":"fail", "reason":"size not set"}'
336336
mimetype = 'text/plain'
337-
self.send_response(mimetype, data)
337+
self.send_response_nc(mimetype, data)
338338
return
339339

340340
buffer_size = reqs["buffer_size"][0]
@@ -349,7 +349,7 @@ def req_log_handler(self):
349349
xlog.error('PAC %s %s %s ', self.address_string(), self.command, self.path)
350350

351351
mimetype = 'text/plain'
352-
self.send_response(mimetype, data)
352+
self.send_response_nc(mimetype, data)
353353

354354
def get_launcher_version(self):
355355
data_path = os.path.abspath( os.path.join(top_path, 'data', 'launcher', 'config.yaml'))
@@ -449,7 +449,7 @@ def req_status_handler(self):
449449
"low_prior_lock": len(connect_control.low_prior_lock),
450450
}
451451
data = json.dumps(res_arr, indent=0, sort_keys=True)
452-
self.send_response('text/html', data)
452+
self.send_response_nc('text/html', data)
453453

454454
def req_config_handler(self):
455455
req = urlparse.urlparse(self.path).query
@@ -468,7 +468,7 @@ def req_config_handler(self):
468468
fail_appid_list = test_appid.test_appids(appids)
469469
if len(fail_appid_list):
470470
fail_appid = "|".join(fail_appid_list)
471-
return self.send_response('text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid)
471+
return self.send_response_nc('text/html', '{"res":"fail", "reason":"appid fail:%s"}' % fail_appid)
472472

473473
appid_updated = True
474474
user_config.user_special.appid = appids
@@ -491,7 +491,7 @@ def req_config_handler(self):
491491
if use_ipv6:
492492
if not check_local_network.check_ipv6():
493493
xlog.warn("IPv6 was enabled, but check failed.")
494-
return self.send_response('text/html', '{"res":"fail", "reason":"IPv6 fail"}')
494+
return self.send_response_nc('text/html', '{"res":"fail", "reason":"IPv6 fail"}')
495495

496496
user_config.user_special.use_ipv6 = use_ipv6
497497

@@ -509,13 +509,13 @@ def req_config_handler(self):
509509
check_ip.load_proxy_config()
510510

511511
data = '{"res":"success"}'
512-
self.send_response('text/html', data)
512+
self.send_response_nc('text/html', data)
513513
#http_request("http://127.0.0.1:8085/init_module?module=gae_proxy&cmd=restart")
514514
return
515515
except Exception as e:
516516
xlog.exception("req_config_handler except:%s", e)
517517
data = '{"res":"fail", "except":"%s"}' % e
518-
self.send_response('text/html', data)
518+
self.send_response_nc('text/html', data)
519519

520520

521521
def req_deploy_handler(self):
@@ -574,7 +574,7 @@ def req_deploy_handler(self):
574574

575575
data = json.dumps({'status': status, 'log': content, 'time': time_now})
576576

577-
self.send_response('text/html', data)
577+
self.send_response_nc('text/html', data)
578578

579579
def req_importip_handler(self):
580580
req = urlparse.urlparse(self.path).query
@@ -602,7 +602,7 @@ def req_importip_handler(self):
602602
data = data[0: len(data) - 1]
603603
data += '"}'
604604

605-
self.send_response('text/html', data)
605+
self.send_response_nc('text/html', data)
606606

607607
def req_test_ip_handler(self):
608608
req = urlparse.urlparse(self.path).query
@@ -616,7 +616,7 @@ def req_test_ip_handler(self):
616616
data = json.dumps("{'ip':'%s', 'handshake':'%s', 'server':'%s', 'domain':'%s'}" %
617617
(ip, result.handshake_time, result.server_type, result.domain))
618618

619-
self.send_response('text/html', data)
619+
self.send_response_nc('text/html', data)
620620

621621
def req_ip_list_handler(self):
622622
time_now = time.time()
@@ -676,7 +676,7 @@ def req_ip_list_handler(self):
676676

677677
data += "</table></div></body></html>"
678678
mimetype = 'text/html'
679-
self.send_response(mimetype, data)
679+
self.send_response_nc(mimetype, data)
680680

681681
def req_scan_ip_handler(self):
682682
req = urlparse.urlparse(self.path).query
@@ -726,7 +726,7 @@ def req_scan_ip_handler(self):
726726
data = scan_ip_log.get_log_content()
727727

728728
mimetype = 'text/plain'
729-
self.send_response(mimetype, data)
729+
self.send_response_nc(mimetype, data)
730730

731731
def req_ssl_pool_handler(self):
732732
data = "New conn:\n"
@@ -740,13 +740,13 @@ def req_ssl_pool_handler(self):
740740
data += https_manager.host_conn_pool[host].to_string()
741741

742742
mimetype = 'text/plain'
743-
self.send_response(mimetype, data)
743+
self.send_response_nc(mimetype, data)
744744

745745
def req_workers_handler(self):
746746
data = http_dispatch.to_string()
747747

748748
mimetype = 'text/plain'
749-
self.send_response(mimetype, data)
749+
self.send_response_nc(mimetype, data)
750750

751751
def req_download_cert_handler(self):
752752
filename = cert_util.CertUtil.ca_keyfile
@@ -761,7 +761,7 @@ def req_is_ready_handler(self):
761761
data = "%s" % config.cert_import_ready
762762

763763
mimetype = 'text/plain'
764-
self.send_response(mimetype, data)
764+
self.send_response_nc(mimetype, data)
765765

766766
def req_check_ip_handler(self):
767767
req = urlparse.urlparse(self.path).query
@@ -772,20 +772,20 @@ def req_check_ip_handler(self):
772772
left_num = google_ip.scan_exist_ip_queue.qsize()
773773
good_num = google_ip.good_ip_num
774774
data = json.dumps(dict(all_ip_num=all_ip_num, left_num=left_num, good_num=good_num))
775-
self.send_response('text/plain', data)
775+
self.send_response_nc('text/plain', data)
776776
elif reqs['cmd'] == ['start']:
777777
left_num = google_ip.scan_exist_ip_queue.qsize()
778778
if left_num:
779-
self.send_response('text/plain', '{"res":"fail", "reason":"running"}')
779+
self.send_response_nc('text/plain', '{"res":"fail", "reason":"running"}')
780780
else:
781781
google_ip.start_scan_all_exist_ip()
782-
self.send_response('text/plain', '{"res":"success"}')
782+
self.send_response_nc('text/plain', '{"res":"success"}')
783783
elif reqs['cmd'] == ['stop']:
784784
left_num = google_ip.scan_exist_ip_queue.qsize()
785785
if not left_num:
786-
self.send_response('text/plain', '{"res":"fail", "reason":"not running"}')
786+
self.send_response_nc('text/plain', '{"res":"fail", "reason":"not running"}')
787787
else:
788788
google_ip.stop_scan_all_exist_ip()
789-
self.send_response('text/plain', '{"res":"success"}')
789+
self.send_response_nc('text/plain', '{"res":"success"}')
790790
else:
791791
return self.send_not_exist()

code/default/python27/1.0/lib/noarch/simple_http_server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ def send_response(self, mimetype="", content="", headers="", status=200):
216216
if len(content):
217217
self.wfile.write(content)
218218

219+
def send_response_nc(self, mimetype="", content="", headers="", status=200):
220+
no_cache_headers = "Cache-Control: no-cache, no-store, must-revalidate\r\nPragma: no-cache\r\nExpires: 0\r\n"
221+
return self.send_response(mimetype, content, no_cache_headers + headers, status)
222+
219223
def send_file(self, filename, mimetype):
220224
try:
221225
if not os.path.isfile(filename):

0 commit comments

Comments
 (0)