Formats the request into a dict representing the headers
        and body that will be used to make the API call.
192426
def request(self, uri, method, *args, **kwargs):
        
        if self.timeout:
            kwargs["timeout"] = self.timeout
        kwargs["verify"] = self.verify_ssl
        kwargs.setdefault("headers", kwargs.get("headers", {}))
        kwargs["headers"]["User-Agent"] = self.user_agent
        kwargs["headers"]["Accept"] = "application/json"
        if ("body" in kwargs) or ("data" in kwargs):
            if "Content-Type" not in kwargs["headers"]:
                kwargs["headers"]["Content-Type"] = "application/json"
            elif kwargs["headers"]["Content-Type"] is None:
                del kwargs["headers"]["Content-Type"]
        # Allow subclasses to add their own headers
        self._add_custom_headers(kwargs["headers"])
        resp, body = pyrax.http.request(method, uri, *args, **kwargs)
        if resp.status_code >= 400:
            raise exc.from_response(resp, body)
        return resp, body
820297
def prepare(self):
        
        super(RequestHandler, self).prepare()
        if self.request.headers.get('content-type', '').startswith(self.JSON):
            self.request.body = escape.json_decode(self.request.body)
949705
def parse_request(self):
        
        data = {}
        options = {}
        ### get data
        if request.headers['Content-Type'].startswith('application/json'):
            # data in JSON
            data = request.json
            assert data is not None #FIXME: better error than assertError ?
            if "options" in data:
                options = data["options"]
                del data["options"]
        else:
            # data in URL/post
            data = dict()
            data.update(request.form)
            data.update(request.args)
            for key, value in six.iteritems(data):
                if isinstance(value, list) and len(value) == 1:
                    data[key] = value[0]
            # manage config in url
            options = self._config_from_url()
        return data, options
96518
def headers_for_url(cls, url):
        """"""
        response = cls.http_request(url, method='HEAD')
        if response.status != 200:
            cls.raise_http_error(response)

        return Resource.headers_as_dict(response)
486644
def format_payload(self, api_version, data):
        
        # Check if payload is for API v1 or API v2.
        if (api_version in (1, 2)):
            # Check if string type.
            if type(data) == str:
                # Convert to dictionary.
                logger.debug('Converting string to dict:\n%s' % data)
                # Remove possible starting question mark & ending ampersands.
                data = data.lstrip('?')
                data = data.rstrip('&')
                # Convert to dictionary.
                data = parse_qs(data)
                logger.debug('Converted:\n%s' % str(data))
        elif api_version in ('am', 'was', 'am2'):
            if type(data) == etree._Element:
                logger.debug('Converting lxml.builder.E to string')
                data = etree.tostring(data)
                logger.debug('Converted:\n%s' % data)
        return data
919365
def make_api_call(self, method, url, json_params=None):
        

        url = self.BRANCH_BASE_URI+url

        if self.verbose is True:
            print("Making web request: {}".format(url))

        if json_params is not None:
            encoded_params = json.dumps(json_params)
            headers = {'Content-Type': 'application/json'}
        else:
            encoded_params = None
            headers = {}

        if encoded_params is not None and self.verbose is True:
            print("Params: {}".format(encoded_params))

        request = Request(url, encoded_params.encode('utf-8'), headers)
        request.get_method = lambda: method
        response = urlopen(request).read()
        return json.loads(response.decode('utf-8'))
154711
def headers(self):
        
        try:
            return self._headers
        except AttributeError:
            self._headers = self._response.headers
            return self._headers
229478
def headers(self):
        """"""
        return {
            "Content-Type": ("multipart/form-data; boundary={}".format(self.boundary)),
            "Content-Length": str(self.len),
            "Content-Encoding": self.encoding,
        }
650389
def get_request_body_chunk(self, content: bytes, closed: bool,
                               more_content: bool) -> Dict[str, Any]:
        '''
        
        '''
        return {
            'content': content,
            'closed': closed,
            'more_content': more_content
        }
747942
def to_header(self):
        """"""
        d = dict(self)
        auth_type = d.pop("__auth_type__", None) or "basic"
        return "%s %s" % (
            auth_type.title(),
            ", ".join(
                [
                    "%s=%s"
                    % (
                        key,
                        quote_header_value(
                            value, allow_token=key not in self._require_quoting
                        ),
                    )
                    for key, value in iteritems(d)
                ]
            ),
        )
191528
def _map_smtp_headers_to_api_parameters(self, email_message):
        
        api_data = []
        for smtp_key, api_transformer in six.iteritems(self._headers_map):
            data_to_transform = email_message.extra_headers.pop(smtp_key, None)
            if data_to_transform is not None:
                if isinstance(data_to_transform, (list, tuple)):
                    # map each value in the tuple/list
                    for data in data_to_transform:
                        api_data.append((api_transformer[0], api_transformer[1](data)))
                elif isinstance(data_to_transform, dict):
                    for data in six.iteritems(data_to_transform):
                        api_data.append(api_transformer(data))
                else:
                    # we only have one value
                    api_data.append((api_transformer[0], api_transformer[1](data_to_transform)))
        return api_data
243223
def parse_request(self, request, parameters=None, fake_method=None):
        '''
        
        '''
        return (request.method,
                request.url,
                request.headers,
                request.POST.mixed())
992331
def format_headers
      @headers.stringify_keys.each_with_object({}) do |key_with_value, headers|
        headers[format_key(key_with_value.first)] = key_with_value.last
      end
    end
180834
protected function formattedRequestBody()
    {
        if (isset($this->payload['options']['body_format']) && $this->payload['options']['body_format'] == 'json') {
            return json_encode($this->payload['parameters']);
        }

        return http_build_query($this->payload['parameters']);
    }
1245168
def headers
      list = @response.header_str.split(/[\r\n]+/).map(&:strip)
      Hash[list.flat_map{ |s| s.scan(/^(\S+): (.+)/) }.map { |pair|
        [pair.first.to_s.camelcase, pair.second]
      }]
    end
119439
def normalize_request_headers(request):
    
    """
    norm_headers = {}
    for header, value in request.META.items():
        if required_header(header):
            norm_header = header.replace('HTTP_', '').title().replace('_', '-')
            norm_headers[norm_header] = value

    return norm_headers
1029753
def headers(self, url):
        
        if self._token and url.lower().startswith('https'):
            return {'Authorization': 'Bearer {}'.format(self._token)}
        else:
            return None