Exemple #1
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl"]

        if self.http_proxy_used:
            if self.proxy_username and self.proxy_password:
                proxy_url = 'http://%s:%s@%s:%s' % (
                    self.proxy_username, self.proxy_password, self.proxy_host,
                    self.proxy_port)
            else:
                proxy_url = 'http://%s:%s' % (self.proxy_host, self.proxy_port)
            proxy_url = pquote(proxy_url)
            cmd.extend(['--proxy', proxy_url])

        cmd.extend(['-i'])

        if method.lower() == 'head':
            # HEAD method need special handling
            cmd.extend(["--head"])
        else:
            cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend(["--compress"])
        cmd.extend([
            pquote("%s://%s:%d%s" % (self.protocol, self.host, self.port, url))
        ])
        return " ".join(cmd)
Exemple #2
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl"]

        if self.http_proxy_used:
            if self.proxy_username and self.proxy_password:
                proxy_url = 'http://%s:%s@%s:%s' % (self.proxy_username,
                                                    self.proxy_password,
                                                    self.proxy_host,
                                                    self.proxy_port)
            else:
                proxy_url = 'http://%s:%s' % (self.proxy_host,
                                              self.proxy_port)
            proxy_url = pquote(proxy_url)
            cmd.extend(['--proxy', proxy_url])

        cmd.extend(['-i'])

        if method.lower() == 'head':
            # HEAD method need special handling
            cmd.extend(["--head"])
        else:
            cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend(["--compress"])
        cmd.extend([pquote("%s://%s:%d%s" % (self.protocol, self.host,
                                             self.port, url))])
        return " ".join(cmd)
Exemple #3
0
  def _to_curl(self, method, url, body, headers):
    cmd = ["curl", "--compressed"]

    cmd.extend(["-X", pquote(method)])

    for h in headers:
      cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

    if body is not None and len(body) > 0:
      cmd.extend(["--data-binary", pquote(body)])
    
    cmd.extend([pquote("https://%s:%d%s" % (self.host, self.port, url))])
    return " ".join(cmd)
Exemple #4
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend([pquote("https://%s:%d%s" % (self.host, self.port, url))])
        return " ".join(cmd)
Exemple #5
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend([pquote("https://%s:%d%s" % (self.host, self.port, url))])
        return " ".join(cmd)
Exemple #6
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        url = pquote(self._get_url(path=url))

        cmd.extend(["--compress"])
        cmd.extend([url])
        return " ".join(cmd)
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        url = pquote(self._get_url(path=url))

        cmd.extend(["--compress"])
        cmd.extend([url])
        return " ".join(cmd)
Exemple #8
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        is_ssl = isinstance(self, LibcloudHTTPSConnection)
        cmd.extend([
            pquote("http%s://%s:%d%s" %
                   (is_ssl and 's' or '', self.host, self.port, url))
        ])
        return " ".join(cmd)
Exemple #9
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        if method.lower() == 'head':
            # HEAD method need special handling
            cmd.extend(["--head"])
        else:
            cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend(["--compress"])
        cmd.extend([pquote("%s://%s:%d%s" % (self.protocol, self.host,
                                             self.port, url))])
        return " ".join(cmd)
Exemple #10
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl", "-i"]

        if method.lower() == 'head':
            # HEAD method need special handling
            cmd.extend(["--head"])
        else:
            cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend(["--compress"])
        cmd.extend([
            pquote("%s://%s:%d%s" % (self.protocol, self.host, self.port, url))
        ])
        return " ".join(cmd)
Exemple #11
0
    def _get_curl_line_for_request(self, request):
        parts = ['curl']

        # method
        method = request.method.upper()
        if method in ['HEAD']:
            parts.extend(['--head'])
        else:
            parts.extend(['-X', pquote(method)])

        # headers
        for key, value in request.headers.items():
            parts.extend(['-H ', pquote('%s: %s' % (key, value))])

        # body
        if request.body:
            parts.extend(['--data-binary', pquote(request.body)])

        # URL
        parts.extend([pquote(request.url)])

        curl_line = ' '.join(parts)
        return curl_line
Exemple #12
0
    def _get_curl_line_for_request(self, request):
        parts = ["curl"]

        # method
        method = request.method.upper()
        if method in ["HEAD"]:
            parts.extend(["--head"])
        else:
            parts.extend(["-X", pquote(method)])

        # headers
        for key, value in request.headers.items():
            parts.extend(["-H ", pquote("%s: %s" % (key, value))])

        # body
        if request.body:
            parts.extend(["--data-binary", pquote(request.body)])

        # URL
        parts.extend([pquote(request.url)])

        curl_line = " ".join(parts)
        return curl_line
Exemple #13
0
    def _get_curl_line_for_request(self, request):
        parts = ['curl']

        # method
        method = request.method.upper()
        if method in ['HEAD']:
            parts.extend(['--head'])
        else:
            parts.extend(['-X', pquote(method)])

        # headers
        for key, value in request.headers.items():
            parts.extend(['-H ', pquote('%s: %s' % (key, value))])

        # body
        if request.body:
            parts.extend(['--data-binary', pquote(request.body)])

        # URL
        parts.extend([pquote(request.url)])

        curl_line = ' '.join(parts)
        return curl_line
Exemple #14
0
    def _get_curl_line_for_request(self, request):
        parts = ["curl"]

        # method
        method = request.method.upper()
        if method in ["HEAD"]:
            parts.extend(["--head"])
        else:
            parts.extend(["-X", pquote(method)])

        # headers
        for key, value in request.headers.items():
            parts.extend(["-H ", pquote("%s: %s" % (key, value))])

        # body
        if request.body:
            parts.extend(["--data-binary", pquote(request.body)])

        # URL
        parts.extend([pquote(request.url)])

        curl_line = " ".join(parts)
        return curl_line
Exemple #15
0
    def _log_curl(self, method, url, body, headers):
        cmd = ["curl"]

        if self.http_proxy_used:
            if self.proxy_username and self.proxy_password:
                proxy_url = "%s://%s:%s@%s:%s" % (
                    self.proxy_scheme,
                    self.proxy_username,
                    self.proxy_password,
                    self.proxy_host,
                    self.proxy_port,
                )
            else:
                proxy_url = "%s://%s:%s" % (
                    self.proxy_scheme,
                    self.proxy_host,
                    self.proxy_port,
                )
            proxy_url = pquote(proxy_url)
            cmd.extend(["--proxy", proxy_url])

        cmd.extend(["-i"])

        if method.lower() == "head":
            # HEAD method need special handling
            cmd.extend(["--head"])
        else:
            cmd.extend(["-X", pquote(method)])

        for h in headers:
            cmd.extend(["-H", pquote("%s: %s" % (h, headers[h]))])

        cert_file = getattr(self, "cert_file", None)

        if cert_file:
            cmd.extend(["--cert", pquote(cert_file)])

        # TODO: in python 2.6, body can be a file-like object.
        if body is not None and len(body) > 0:
            if isinstance(body, (bytearray, bytes)):
                body = body.decode("utf-8")

            cmd.extend(["--data-binary", pquote(body)])

        cmd.extend(["--compress"])
        cmd.extend([pquote("%s%s" % (self.host, url))])
        return " ".join(cmd)