Construct a ``TraceHeader`` object from dictionary headers
    of the incoming request. This method should always return
    a ``TraceHeader`` object regardless of tracing header's presence
    in the incoming request.
189204
def construct_xray_header(headers):
    
    header_str = headers.get(http.XRAY_HEADER) or headers.get(http.ALT_XRAY_HEADER)
    if header_str:
        return TraceHeader.from_header_str(header_str)
    else:
        return TraceHeader()
8578
def parse_request_headers(headers):
    
    request_header_keys = set(headers.keys(lower=True))
    request_meta_keys = set(XHEADERS_TO_ARGS_DICT.keys())
    data_header_keys = request_header_keys.intersection(request_meta_keys)
    return dict(([XHEADERS_TO_ARGS_DICT[key],
                  headers.get(key, None)] for key in data_header_keys))
891525
def _generate_request_head_bytes(method, endpoint, headers):
    

    head_string = _FORMAT_METHOD_AND_ENDPOINT.format(method, endpoint)
    header_tuples = sorted((k, headers[k]) for k in headers)

    for name, value in header_tuples:
        if _should_sign_request_header(name):
            head_string += _FORMAT_HEADER_STRING.format(name, value)

    return (head_string + _DELIMITER_NEWLINE).encode()
1184528
def inject(cls, span, obj):
        
        opentracing.tracer.inject(span, cls.FORMAT, obj['headers'])
619309
def get_header(request, header_service):
    
    service = request.META.get('HTTP_{}'.format(header_service), b'')
    if isinstance(service, str):
        # Work around django test client oddness
        service = service.encode(HTTP_HEADER_ENCODING)
    return service
428188
def from_headers (strheader):
    
    res = []
    fp = StringIO(strheader)
    headers = httplib.HTTPMessage(fp, seekable=True)
    if "Host" not in headers:
        raise ValueError("Required header 'Host:' missing")
    host = headers["Host"]
    path= headers.get("Path", "/")
    for header in headers.getallmatchingheaders("Set-Cookie"):
        headervalue = header.split(':', 1)[1]
        for pairs in cookielib.split_header_words([headervalue]):
            for name, value in pairs:
                cookie = requests.cookies.create_cookie(name, value,
                    domain=host, path=path)
                res.append(cookie)
    return res
854117
def lookup_from_headers(cls, headers):
        

        # A single address, set by this server, returned as an Array
        remote_addr = cls.ips_from(headers.get("REMOTE_ADDR"))

        # Could be a CSV list and/or repeated headers that were concatenated.
        forwarded_ips = cls.ips_from(headers.get("HTTP_X_FORWARDED_FOR"))
        client_ips = cls.ips_from(headers.get("HTTP_CLIENT_IP"))

        # We assume these things about the IP headers:
        #
        #   - X-Forwarded-For will be a list of IPs, one per proxy, or blank.
        #       in order: `client,proxy1,proxy2`
        #   - Client-Ip is propagated from the outermost proxy, or is blank
        #   - REMOTE_ADDR will be the IP that made the request to this server
        #
        # X-Forwarded-For and Client-Ip shouldn't be set at the same time, but
        # if they are, use the one in Forwarded
        ips = forwarded_ips + client_ips + remote_addr

        try:
            return ips[0]
        except IndexError:
            return None
1271705
def getheader(self, header, default=None):
        '''
        
        '''
        if isinstance(header, str):
            return self.headers.get(header.lower(), default)
        return self.__rawheaders.get(header, default)
736582
def trace(self, *attributes):
        
        def decorator(f):
            def wrapper(*args, **kwargs):
                if self._trace_all_requests:
                    return f(*args, **kwargs)

                self._before_request_fn(list(attributes))
                try:
                    r = f(*args, **kwargs)
                    self._after_request_fn()
                except Exception as e:
                    self._after_request_fn(error=e)
                    raise

                self._after_request_fn()
                return r

            wrapper.__name__ = f.__name__
            return wrapper
        return decorator
1276954
def clean_headers(self):
        """"""
        if not isinstance(self.request.get('headers'), dict):
            return self
        headers = self.request['headers']
        if 'Cookie' in headers:
            self.clean_cookie()
        for key in headers:
            # cookie will be checked in other methods.
            if key == 'Cookie':
                continue
            new_request = deepcopy(self.request)
            new_headers = deepcopy(headers)
            new_headers.pop(key)
            new_request['headers'] = new_headers
            self._add_task('headers', key, new_request)
        return self
259587
def from_traceback(cls, tb):
        """"""
        stack_trace = cls(
            stack_trace_hash_id=generate_hash_id_from_traceback(tb)
        )
        # use the add_stack_frame so that json formatting is applied
        for tb_frame_info in traceback.extract_tb(tb):
            filename, line_num, fn_name, _ = tb_frame_info
            stack_trace.add_stack_frame(
                StackFrame(
                    func_name=fn_name,
                    original_func_name=fn_name,
                    file_name=filename,
                    line_num=line_num,
                    col_num=0,  # I don't think this is available in python
                    load_module=filename,
                    build_id=BUILD_ID,
                    source_version=SOURCE_VERSION
                )
            )
        return stack_trace
537940
private <RequestT, ResponseT>
      ServerStreamingCallable<RequestT, ResponseT> createUserFacingServerStreamingCallable(
          String methodName, ServerStreamingCallable<RequestT, ResponseT> inner) {

    ServerStreamingCallable<RequestT, ResponseT> traced =
        new TracedServerStreamingCallable<>(
            inner,
            clientContext.getTracerFactory(),
            SpanName.of(TRACING_OUTER_CLIENT_NAME, methodName));

    return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
  }
1042
def get_request(request_url, request_headers=dict()):
    
    request = Request(request_url)
    for key, val in request_headers.items():
        request.add_header(key, val)

    try:
        response = urlopen(request, timeout=_REQUEST_TIMEOUT)
        response_content = response.read()
    except (HTTPError, URLError, socket.timeout):
        response_content = None

    return response_content
216738
def _get_header_url(response, header_name):
    
    url = response.headers.get(header_name)
    try:
        _validate(url)
    except ValueError:
        return None
    else:
        return url
1139817
def with_headers(self, headers=None, **params):
                
        if isinstance(headers, (tuple, list)):
            headers = dict(headers)

        if params:
            if isinstance(headers, dict):
                headers.update(params)
            elif headers is None:
                headers = params

        self._headers.update(headers)
        return self
429822
def get_header(self, name, default=None):
        
        return self._handler.headers.get(name, default)
1335005
def get_header(self, header_name):
        
        if header_name in self.headers:
            return self.headers[header_name]
        return self.add_header_name(header_name)