Example #1
0
    def http_request(self, path="/", method="GET", host=None, port=None, json=False, data=None):
        """
        perform a HTTP request

        :param path: str, path within the reqest, e.g. "/api/version"
        :param method: str, HTTP method
        :param host: str, if None, set self.get_IPv4s()[0]
        :param port: str or int, if None, set to self.get_ports()[0]
        :param json: bool, should we expect json?
        :param data: data to send (can be dict, list, str)
        :return: dict
        """
        host = host or self.get_IPv4s()[0]
        port = port or self.get_ports()[0]
        url = get_url(host=host, port=port, path=path)

        return self.http_session.request(method, url, json=json, data=data)
Example #2
0
def test_http_client_get_url():
    assert get_url(path="/", host="172.1.1.1",
                   port=80) == "http://172.1.1.1:80/"
    assert get_url(path="/app", host="domain.example.org",
                   port=443) == "http://domain.example.org:443/app"