commit 66e893f1d41a48c638a99c1e5b7148ab5dba37a2
parent a68a53c59e25a35c1671ae5aca2a70d935c3e20d
Author: Joris Vink <joris@coders.se>
Date: Sat, 4 Mar 2023 23:15:49 +0100
Python API domain improvement.
Add redirect() method to add a redirect on a domain much like
in the Kore configuration file.
eg:
domain.redirect("^/account/(.*)$", 301, "https://site/account/$1")
Diffstat:
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h
@@ -231,10 +231,12 @@ struct pydomain {
};
static PyObject *pydomain_filemaps(struct pydomain *, PyObject *);
+static PyObject *pydomain_redirect(struct pydomain *, PyObject *);
static PyObject *pydomain_route(struct pydomain *, PyObject *, PyObject *);
static PyMethodDef pydomain_methods[] = {
METHOD("filemaps", pydomain_filemaps, METH_VARARGS),
+ METHOD("redirect", pydomain_redirect, METH_VARARGS),
METHOD("route", pydomain_route, METH_VARARGS | METH_KEYWORDS),
METHOD(NULL, NULL, -1)
};
diff --git a/src/python.c b/src/python.c
@@ -5617,6 +5617,23 @@ pydomain_filemaps(struct pydomain *domain, PyObject *args)
}
static PyObject *
+pydomain_redirect(struct pydomain *domain, PyObject *args)
+{
+ int status;
+ const char *src, *dst;
+
+ if (!PyArg_ParseTuple(args, "sis", &src, &status, &dst))
+ return (NULL);
+
+ if (!http_redirect_add(domain->config, src, status, dst)) {
+ fatal("failed to add redirect '%s' on '%s'",
+ src, domain->config->domain);
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
pydomain_route(struct pydomain *domain, PyObject *args, PyObject *kwargs)
{
PyObject *obj;