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")
This commit is contained in:
Joris Vink 2023-03-04 23:15:49 +01:00
parent a68a53c59e
commit 66e893f1d4
2 changed files with 19 additions and 0 deletions

View File

@ -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)
};

View File

@ -5616,6 +5616,23 @@ pydomain_filemaps(struct pydomain *domain, PyObject *args)
Py_RETURN_NONE;
}
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)
{