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 ff19ce76521ef34ba5a674f0a51c1092ab4eea69
parent a3800fa57e9cfb98809ae0d53a5af7f0b27e343f
Author: Joris Vink <joris@coders.se>
Date:   Fri, 17 Dec 2021 16:52:13 +0100

Python: add a protocol member to kore.httprequest

This returns a string depending on the protocol used (https / http) for
the HTTP request.

Diffstat:
include/kore/python_methods.h | 2++
src/python.c | 16++++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h @@ -780,6 +780,7 @@ static PyObject *pyhttp_get_path(struct pyhttp_request *, void *); static PyObject *pyhttp_get_body(struct pyhttp_request *, void *); static PyObject *pyhttp_get_agent(struct pyhttp_request *, void *); static PyObject *pyhttp_get_method(struct pyhttp_request *, void *); +static PyObject *pyhttp_get_protocol(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 *); @@ -790,6 +791,7 @@ static PyGetSetDef pyhttp_request_getset[] = { GETTER("body", pyhttp_get_body), GETTER("agent", pyhttp_get_agent), GETTER("method", pyhttp_get_method), + GETTER("protocol", pyhttp_get_protocol), GETTER("body_path", pyhttp_get_body_path), GETTER("body_digest", pyhttp_get_body_digest), GETTER("connection", pyhttp_get_connection), diff --git a/src/python.c b/src/python.c @@ -5172,6 +5172,22 @@ pyhttp_get_method(struct pyhttp_request *pyreq, void *closure) } static PyObject * +pyhttp_get_protocol(struct pyhttp_request *pyreq, void *closure) +{ + struct connection *c; + const char *proto; + + c = pyreq->req->owner; + + if (c->owner->server->tls) + proto = "https"; + else + proto = "http"; + + return (PyUnicode_FromString(proto)); +} + +static PyObject * pyhttp_get_body_path(struct pyhttp_request *pyreq, void *closure) { if (pyreq->req->http_body_path == NULL) {