Python: add a protocol member to kore.httprequest

This returns a string depending on the protocol used (https / http) for
the HTTP request.
This commit is contained in:
Joris Vink 2021-12-17 16:52:13 +01:00
parent a3800fa57e
commit ff19ce7652
2 changed files with 18 additions and 0 deletions

View File

@ -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),

View File

@ -5171,6 +5171,22 @@ pyhttp_get_method(struct pyhttp_request *pyreq, void *closure)
return (PyLong_FromUnsignedLong(pyreq->req->method));
}
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)
{