def compose_headers(self, req, headers=None, opt=None, as_dict=False):
        """ a utility to compose headers from pyswagger.io.Request and customized headers

        :return: list of tuple (key, value) when as_dict is False, else dict
        """
        if headers is None:
            return list(req.header.items()) if not as_dict else req.header

        opt = opt or {}
        join_headers = opt.pop(BaseClient.join_headers, None)
        if as_dict and not join_headers:
            # pick the most efficient way for special case
            headers = dict(headers) if isinstance(headers, list) else headers
            headers.update(req.header)
            return headers

        # include Request.headers
        aggregated_headers = list(req.header.items())

        # include customized headers
        if isinstance(headers, list):
            aggregated_headers.extend(headers)
        elif isinstance(headers, dict):
            aggregated_headers.extend(headers.items())
        else:
            raise Exception('unknown type as header: {}'.format(str(type(headers))))

        if join_headers:
            joined = {}
            for h in aggregated_headers:
                key = h[0]
                if key in joined:
                    joined[key] = ','.join([joined[key], h[1]])
                else:
                    joined[key] = h[1]
            aggregated_headers = list(joined.items())

        return dict(aggregated_headers) if as_dict else aggregated_headers
def compose_headers ( self , req , headers = None , opt = None , as_dict = False ) : if headers is None : return list ( req . header . items ( ) ) if not as_dict else req . header opt = opt or { } join_headers = opt . pop ( BaseClient . join_headers , None ) if as_dict and not join_headers : headers = dict ( headers ) if isinstance ( headers , list ) else headers headers . update ( req . header ) return headers aggregated_headers = list ( req . header . items ( ) ) if isinstance ( headers , list ) : aggregated_headers . extend ( headers ) elif isinstance ( headers , dict ) : aggregated_headers . extend ( headers . items ( ) ) else : raise Exception ( 'unknown type as header: {}' . format ( str ( type ( headers ) ) ) ) if join_headers : joined = { } for h in aggregated_headers : key = h [ 0 ] if key in joined : joined [ key ] = ',' . join ( [ joined [ key ] , h [ 1 ] ] ) else : joined [ key ] = h [ 1 ] aggregated_headers = list ( joined . items ( ) ) return dict ( aggregated_headers ) if as_dict else aggregated_headers
a utility to compose headers from pyswagger.io.Request and customized headers

        :return: list of tuple (key, value) when as_dict is False, else dict