# Keep-alive connections for httpapi plugins

**URL:** <https://forum.ansible.com/t/keep-alive-connections-for-httpapi-plugins/33237>\
**Category:** Ansible Developer\
**Created:** [June 23, 2020, 4:42pm UTC](https://forum.ansible.com/t/keep-alive-connections-for-httpapi-plugins/33237 "2020-06-23T16:42:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandru\_Obretin](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Alexandru\_Obretin](https://forum.ansible.com/u/Alexandru_Obretin)\
**Post date:** [June 23, 2020, 4:42pm UTC](https://forum.ansible.com/t/keep-alive-connections-for-httpapi-plugins/33237/1 "2020-06-23T16:42:51Z")

</div>

Hello,

I am working on a custom HTTP connection plugin and some related modules in order to access a proprietary REST API. For this purpose, I have to provide capabilities for basic create/update/delete operations on different entities.

While developing the plugin, I have noticed the standard httpapi implimentation is relying on urllib\_request.urlopen inside the open() method from module\_utils/urls.py.

Further, the AbstractHTTPHandler provided by the urllib\_request has the following limitation:

# TODO(jhylton): Should this be redesigned to handle

# persistent connections?

# We want to make an HTTP/1.1 request, but the addinfourl

# class isn’t prepared to deal with a persistent connection.

# It will try to read all remaining data from the socket,

# which will block while the server waits for the next request.

# So make sure the connection gets closed after the (only)

# request.

headers[“Connection”] = “close”

Therefore, I cannot create ‘keep-alive’ connections which further interferes with PUT or POST requests that have a payload which is send to the server in a separate request - check implementation in /usr/lib/python3/http/client.py, \_send\_output() method.

Under these circumstances, is there any way to use urllib3 in Ansible for http connections? Or any workaround to keep the connection alive until the payload is send to the server?

Thank you for your time!

Regards,  
Alex
