kore

a fork of the worlds most advanced web framework
Log | Files | Refs | README | LICENSE

commit a6af458cd2cb143fa605dcff3b39096b2d2d6534
parent 9718d6b7bb4998e7cb0715c22e67552e1bdae9f2
Author: Joris Vink <joris@coders.se>
Date:   Wed, 24 Apr 2019 18:28:23 +0200

add tlsverify keyword to kore.httpclient().

Diffstat:
Minclude/kore/python_methods.h | 1+
Msrc/python.c | 21+++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/kore/python_methods.h b/include/kore/python_methods.h @@ -654,6 +654,7 @@ struct pyhttp_client { char *url; char *tlscert; char *tlskey; + int tlsverify; }; #define PYHTTP_CLIENT_OP_RUN 1 diff --git a/src/python.c b/src/python.c @@ -3774,6 +3774,7 @@ python_kore_httpclient(PyObject *self, PyObject *args, PyObject *kwargs) if (client == NULL) return (NULL); + client->tlsverify = 1; client->tlskey = NULL; client->tlscert = NULL; client->url = kore_strdup(url); @@ -3796,6 +3797,19 @@ python_kore_httpclient(PyObject *self, PyObject *args, PyObject *kwargs) client->tlskey = kore_strdup(v); } + + if ((obj = PyDict_GetItemString(kwargs, "tlsverify")) != NULL) { + if (item == Py_True) { + client->tlsverify = 1; + } else if (item == Py_False) { + client->tlsverify = 0; + } else { + Py_DECREF((PyObject *)client); + PyErr_SetString(PyExc_RuntimeError, + "tlsverify not True or False"); + return (NULL); + } + } } if ((client->tlscert != NULL && client->tlskey == NULL) || @@ -3948,6 +3962,13 @@ pyhttp_client_request(struct pyhttp_client *client, int m, PyObject *kwargs) client->tlscert); curl_easy_setopt(op->curl.handle, CURLOPT_SSLKEY, client->tlskey); + + if (client->tlsverify == 0) { + curl_easy_setopt(op->curl.handle, + CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(op->curl.handle, + CURLOPT_SSL_VERIFYPEER, 0); + } } if (headers != NULL) {