diff src/server/server.py @ 955:4f7cb6335a33

server(pages): do Post/Redirect/Get pattern when on_data_post is used (avoid double posting on refresh)
author Goffi <goffi@goffi.org>
date Sun, 09 Jul 2017 22:28:40 +0200
parents 67a59552f3e3
children dabecab10faa
line wrap: on
line diff
--- a/src/server/server.py	Fri Jul 07 07:28:42 2017 +0200
+++ b/src/server/server.py	Sun Jul 09 22:28:40 2017 +0200
@@ -1690,8 +1690,14 @@
             msg = failure_))
         self.pageError(request, C.HTTP_INTERNAL_ERROR)
 
+    @defer.inlineCallbacks
     def _on_data_post(self, dummy, request):
-        return defer.maybeDeferred(self.on_data_post, self, request)
+        yield defer.maybeDeferred(self.on_data_post, self, request)
+        request.setResponseCode(303)
+        request.setHeader("location", request.uri)
+        request.finish()
+        raise failure.Failure(exceptions.CancelError(u'Post/Redirect/Get is used'))
+
 
     def getPostedData(self, request, keys, multiple=False):
         """get data from a POST request and decode it