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 9845c8bbe1e68867fb06e826536bfd661d1a59df
parent 774cc56ed257aed6f744768dd8d35ac4fa5bdb04
Author: Joris Vink <joris@coders.se>
Date:   Mon, 13 Dec 2021 10:45:00 +0100

Python: Add req.body_digest.

Returns the SHA256 digest of the uploaded body as a bytes object.

Diffstat:
include/kore/python_methods.h | 2++
src/python.c | 34+++++++++++++---------------------
2 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h @@ -782,6 +782,7 @@ static PyObject *pyhttp_get_agent(struct pyhttp_request *, void *); static PyObject *pyhttp_get_method(struct pyhttp_request *, void *); static PyObject *pyhttp_get_body_path(struct pyhttp_request *, void *); static PyObject *pyhttp_get_connection(struct pyhttp_request *, void *); +static PyObject *pyhttp_get_body_digest(struct pyhttp_request *, void *); static PyGetSetDef pyhttp_request_getset[] = { GETTER("host", pyhttp_get_host), @@ -790,6 +791,7 @@ static PyGetSetDef pyhttp_request_getset[] = { GETTER("agent", pyhttp_get_agent), GETTER("method", pyhttp_get_method), GETTER("body_path", pyhttp_get_body_path), + GETTER("body_digest", pyhttp_get_body_digest), GETTER("connection", pyhttp_get_connection), GETTER(NULL, NULL) }; diff --git a/src/python.c b/src/python.c @@ -5109,42 +5109,34 @@ pyhttp_get_body(struct pyhttp_request *pyreq, void *closure) static PyObject * pyhttp_get_agent(struct pyhttp_request *pyreq, void *closure) { - PyObject *agent; - - if (pyreq->req->agent == NULL) { - Py_RETURN_NONE; - } - - if ((agent = PyUnicode_FromString(pyreq->req->path)) == NULL) - return (PyErr_NoMemory()); - - return (agent); + return (PyUnicode_FromString(pyreq->req->path)); } static PyObject * pyhttp_get_method(struct pyhttp_request *pyreq, void *closure) { - PyObject *method; - - if ((method = PyLong_FromUnsignedLong(pyreq->req->method)) == NULL) - return (PyErr_NoMemory()); - - return (method); + return (PyLong_FromUnsignedLong(pyreq->req->method)); } static PyObject * pyhttp_get_body_path(struct pyhttp_request *pyreq, void *closure) { - PyObject *path; - if (pyreq->req->http_body_path == NULL) { Py_RETURN_NONE; } - if ((path = PyUnicode_FromString(pyreq->req->http_body_path)) == NULL) - return (PyErr_NoMemory()); + return (PyUnicode_FromString(pyreq->req->http_body_path)); +} - return (path); +static PyObject * +pyhttp_get_body_digest(struct pyhttp_request *pyreq, void *closure) +{ + PyObject *digest; + + digest = PyBytes_FromStringAndSize((char *)pyreq->req->http_body_digest, + sizeof(pyreq->req->http_body_digest)); + + return (digest); } static PyObject *