kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 95139925ec82fe71d451114a72c1b6c0fae90677
parent f1a65ef2368d6704edad84176c86068249e25678
Author: Joris Vink <joris@coders.se>
Date:   Fri, 18 Jun 2021 13:00:57 +0200

Add query string support to the Python validator API.

Now you can specify the qs keyword in a route which can contain
validators for the query string.

Eg:

@kore.route("/", methods=["post"], qs={"id": "^[0-9]+$"})
def index:
    ...

Diffstat:
src/python.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/python.c b/src/python.c @@ -81,7 +81,8 @@ static struct kore_domain *python_route_domain_resolve(struct pyroute *); static int python_route_install(struct pyroute *); static int python_route_params(PyObject *, - struct kore_module_handle *, const char *, int); + struct kore_module_handle *, const char *, + int, int); static int python_route_methods(PyObject *, PyObject *, struct kore_module_handle *); static int python_route_auth(PyObject *, @@ -5267,7 +5268,10 @@ python_route_methods(PyObject *obj, PyObject *kwargs, if (method == HTTP_METHOD_GET) hdlr->methods |= HTTP_METHOD_HEAD; - if (!python_route_params(kwargs, hdlr, val, method)) + if (!python_route_params(kwargs, hdlr, val, method, 0)) + return (KORE_RESULT_ERROR); + + if (!python_route_params(kwargs, hdlr, "qs", method, 1)) return (KORE_RESULT_ERROR); } @@ -5276,7 +5280,7 @@ python_route_methods(PyObject *obj, PyObject *kwargs, static int python_route_params(PyObject *kwargs, struct kore_module_handle *hdlr, - const char *method, int type) + const char *method, int type, int qs) { Py_ssize_t idx; const char *val; @@ -5336,7 +5340,7 @@ python_route_params(PyObject *kwargs, struct kore_module_handle *hdlr, param->validator = vldr; param->name = kore_strdup(val); - if (type == HTTP_METHOD_GET) + if (type == HTTP_METHOD_GET || qs == 1) param->flags = KORE_PARAMS_QUERY_STRING; TAILQ_INSERT_TAIL(&hdlr->params, param, list);