diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h index 4c7a1fd..0c06cff 100644 --- 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 index 312e410..ed00c3f 100644 --- a/src/python.c +++ b/src/python.c @@ -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) {