add tlsverify keyword to kore.httpclient().

This commit is contained in:
Joris Vink 2019-04-24 18:28:23 +02:00
parent 9718d6b7bb
commit a6af458cd2
2 changed files with 22 additions and 0 deletions

View File

@ -654,6 +654,7 @@ struct pyhttp_client {
char *url;
char *tlscert;
char *tlskey;
int tlsverify;
};
#define PYHTTP_CLIENT_OP_RUN 1

View File

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