mirror of https://git.kore.io/kore.git
add option to use unix paths via kore.httpclient
This commit is contained in:
parent
3c9a141cd0
commit
fe84997ce9
|
@ -659,6 +659,7 @@ static PyTypeObject pyhttp_file_type = {
|
||||||
struct pyhttp_client {
|
struct pyhttp_client {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
char *url;
|
char *url;
|
||||||
|
char *unix;
|
||||||
char *tlskey;
|
char *tlskey;
|
||||||
char *tlscert;
|
char *tlscert;
|
||||||
char *cabundle;
|
char *cabundle;
|
||||||
|
|
28
src/python.c
28
src/python.c
|
@ -3141,6 +3141,8 @@ pyhttp_response(struct pyhttp_request *pyreq, PyObject *args)
|
||||||
|
|
||||||
http_response_stream(pyreq->req, status, ptr, length,
|
http_response_stream(pyreq->req, status, ptr, length,
|
||||||
pyhttp_response_sent, obj);
|
pyhttp_response_sent, obj);
|
||||||
|
} else if (obj == Py_None) {
|
||||||
|
http_response(pyreq->req, status, NULL, 0);
|
||||||
} else {
|
} else {
|
||||||
if ((iterator = PyObject_GetIter(obj)) == NULL)
|
if ((iterator = PyObject_GetIter(obj)) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
@ -4010,6 +4012,7 @@ python_kore_httpclient(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
if (client == NULL)
|
if (client == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
|
client->unix = NULL;
|
||||||
client->tlskey = NULL;
|
client->tlskey = NULL;
|
||||||
client->tlscert = NULL;
|
client->tlscert = NULL;
|
||||||
client->cabundle = NULL;
|
client->cabundle = NULL;
|
||||||
|
@ -4045,6 +4048,15 @@ python_kore_httpclient(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
client->cabundle = kore_strdup(v);
|
client->cabundle = kore_strdup(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((obj = PyDict_GetItemString(kwargs, "unix")) != NULL) {
|
||||||
|
if ((v = PyUnicode_AsUTF8(obj)) == NULL) {
|
||||||
|
Py_DECREF((PyObject *)client);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
client->unix = kore_strdup(v);
|
||||||
|
}
|
||||||
|
|
||||||
if ((obj = PyDict_GetItemString(kwargs, "tlsverify")) != NULL) {
|
if ((obj = PyDict_GetItemString(kwargs, "tlsverify")) != NULL) {
|
||||||
if (obj == Py_True) {
|
if (obj == Py_True) {
|
||||||
client->tlsverify = 1;
|
client->tlsverify = 1;
|
||||||
|
@ -4074,6 +4086,7 @@ static void
|
||||||
pyhttp_client_dealloc(struct pyhttp_client *client)
|
pyhttp_client_dealloc(struct pyhttp_client *client)
|
||||||
{
|
{
|
||||||
kore_free(client->url);
|
kore_free(client->url);
|
||||||
|
kore_free(client->unix);
|
||||||
kore_free(client->tlskey);
|
kore_free(client->tlskey);
|
||||||
kore_free(client->tlscert);
|
kore_free(client->tlscert);
|
||||||
kore_free(client->cabundle);
|
kore_free(client->cabundle);
|
||||||
|
@ -4205,6 +4218,21 @@ pyhttp_client_request(struct pyhttp_client *client, int m, PyObject *kwargs)
|
||||||
kore_curl_bind_callback(&op->curl, python_curl_callback, op);
|
kore_curl_bind_callback(&op->curl, python_curl_callback, op);
|
||||||
|
|
||||||
/* Go in with our own bare hands. */
|
/* Go in with our own bare hands. */
|
||||||
|
if (client->unix != NULL) {
|
||||||
|
#if defined(__linux__)
|
||||||
|
if (client->unix[0] == '@') {
|
||||||
|
curl_easy_setopt(op->curl.handle,
|
||||||
|
CURLOPT_ABSTRACT_UNIX_SOCKET, client->unix + 1);
|
||||||
|
} else {
|
||||||
|
curl_easy_setopt(op->curl.handle,
|
||||||
|
CURLOPT_UNIX_SOCKET_PATH, client->unix);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
curl_easy_setopt(op->curl.handle, CURLOPT_UNIX_SOCKET_PATH,
|
||||||
|
client->unix);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (client->tlskey != NULL && client->tlscert != NULL) {
|
if (client->tlskey != NULL && client->tlscert != NULL) {
|
||||||
curl_easy_setopt(op->curl.handle, CURLOPT_SSLCERT,
|
curl_easy_setopt(op->curl.handle, CURLOPT_SSLCERT,
|
||||||
client->tlscert);
|
client->tlscert);
|
||||||
|
|
Loading…
Reference in New Issue