mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 04:29:02 -04:00
Python: Add req.body_digest.
Returns the SHA256 digest of the uploaded body as a bytes object.
This commit is contained in:
parent
774cc56ed2
commit
9845c8bbe1
@ -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)
|
||||
};
|
||||
|
34
src/python.c
34
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 *
|
||||
|
Loading…
x
Reference in New Issue
Block a user