Exemplo n.º 1
0
    def _make_http_response(self, endpoint, request, specific_signer=None):
        body_params = request.get_body_params()
        if body_params:
            body = urllib.parse.urlencode(body_params)
            request.set_content(body)
            request.set_content_type(format_type.APPLICATION_FORM)
        elif request.get_content() and "Content-Type" not in request.get_headers():
            request.set_content_type(format_type.APPLICATION_OCTET_STREAM)
        method = request.get_method()

        signer = self._signer if specific_signer is None else specific_signer
        header, url = signer.sign(self.__region_id, request)

        if self.get_user_agent() is not None:
            header['User-Agent'] = self.get_user_agent()
        if header is None:
            header = {}
        header['x-sdk-client'] = 'python/2.0.0'

        protocol = request.get_protocol_type()
        response = HttpResponse(
            endpoint,
            url,
            method,
            header,
            protocol,
            request.get_content(),
            self._port,
            timeout=self._timeout)
        if body_params:
            body = urllib.parse.urlencode(request.get_body_params())
            response.set_content(body, "utf-8", format_type.APPLICATION_FORM)
        return response
Exemplo n.º 2
0
 def run(self, view):
     if (self.view.file_name()):
         path = settings.get('path')
         hostname = settings.get('hostname')
         port = settings.get('port')
         endpoint = settings.get('endpoint')
         url = 'http://' + hostname + ':' + str(
             port) + endpoint + '?filePath=' + self.view.file_name(
             ).replace(path, '')
         print(url)
         data = self.view.substr(sublime.Region(0, self.view.size()))
         request = HttpAsyncRequest(url)
         request.set_content(str.encode(data))
         request.set_header('Content-type', 'text/plain')
         request.send()