kea_connector2.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
  2. #
  3. # This Source Code Form is subject to the terms of the Mozilla Public
  4. # License, v. 2.0. If a copy of the MPL was not distributed with this
  5. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. """
  7. This is PYTHON 2.x version of HTTP connection establishment
  8. """
  9. import httplib
  10. from kea_conn import CAResponse # CARequest
  11. def send_to_control_agent(params):
  12. """ Sends a request to Control Agent, receives a response and returns it."""
  13. # Establish HTTP connection first.
  14. conn = httplib.HTTPConnection(params.http_host, params.http_port)
  15. conn.connect()
  16. # Use POST to send it
  17. _ = conn.putrequest('POST', params.path)
  18. # Send the headers first
  19. for k in params.headers:
  20. conn.putheader(k, params.headers[k])
  21. conn.endheaders()
  22. # Send the body (i.e. the actual content)
  23. conn.send(params.content)
  24. # Now get the response
  25. resp = conn.getresponse()
  26. # Now get the response details, put it in CAResponse and
  27. # return it
  28. result = CAResponse(resp.status, resp.reason, resp.read())
  29. conn.close()
  30. return result