Zeronet: [Enhancement] Possibility for a page to access post data

Created on 6 Sep 2018  路  3Comments  路  Source: HelloZeroNet/ZeroNet

Especially useful if we really want to have Error-collection sites as per #1553, since GET request length has limits for some browsers.
Zeronet should insert that as a page special variable or send it to the page on request (e.g. getPostData).

A reference for url length

All 3 comments

I tried writing an example for the code, but it does not work as it is.
The problem is that the field "wsgi.input" (where post data is found) is not transferred from UiRequest (where the initial request really is) to UiWebSocket (where the request to "getPostData" really happens).

diff --git a/src/Ui/UiWebsocket.py b/src/Ui/UiWebsocket.py
index b6e7615..7c616a4 100644
--- a/src/Ui/UiWebsocket.py
+++ b/src/Ui/UiWebsocket.py
@@ -338,6 +338,12 @@ class UiWebsocket(object):

     # - Actions -

+    # Returns the request body
+    def actionGetPostData(self, to):
+        # TODO: Here we don't have wsgi.input cause this is the request to the websocket
+        input_data = self.request.env["wsgi.input"].read()
+        return self.response(to, input_data)
+    
     def actionAs(self, to, address, cmd, params=[]):
         if not self.hasSitePermission(address, cmd=cmd):
             return self.response(to, "No permission for site %s" % address)

Should I add a field to the UiServer to store post data?
How should I proceed?

You can store in a variable based on wrapper_nonce, then read it later from websocket, but it may require other changes. Websocket is not really suitable to sending big data, so I don't recommend to use it that way. Instead I would recommend to use the BigFile plugin for this, that has post support and streaming file writing: https://zeronet.readthedocs.io/en/latest/site_development/zeroframe_api_reference/#bigfileuploadinit-inner_path-size

Ok, now I can't really think of a use case where reading post data should be necessary.
I'm going to close this issue if noone comes out with a reasonable one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BenMcLean picture BenMcLean  路  3Comments

DaniellMesquita picture DaniellMesquita  路  3Comments

Forbo picture Forbo  路  3Comments

sergei-bondarenko picture sergei-bondarenko  路  3Comments

iShift picture iShift  路  3Comments