Gets a forwarded value from the `Forwarded` header if present, or
        the equivalent `X-Forwarded-` header if not. If neither is present,
        returns an empty string.
172826
def _get_forwarded(request, key):
        
        forwarded = request.headers.get('Forwarded', '')
        match = re.search(
            r'(?<={}=).+?(?=[\s,;]|$)'.format(key),
            forwarded,
            re.IGNORECASE)

        if match is not None:
            header = match.group(0)

            if header[0] == '"' and header[-1] == '"':
                return header[1:-1]

            return header

        return request.headers.get('X-Forwarded-{}'.format(key.title()), '')
663154
def _get_ip_address(self, request):
        
        ipaddr = request.META.get("HTTP_X_FORWARDED_FOR", None)
        if ipaddr:
            # X_FORWARDED_FOR returns client1, proxy1, proxy2,...
            return ipaddr.split(",")[0].strip()
        return request.META.get("REMOTE_ADDR", "")
16131
public void transformAndSetForwardedHeader() {
        if (xForwardedForHeader != null && xForwardedByHeader != null) {
            //Transition is not done, as it's not possible to know in which order the existing fields were added.
            LOG.info("Header transition is not done as both X-Forwarded-For and X-Forwarded-By headers are present.");
            return;
        }
        StringBuilder headerValue = new StringBuilder();
        if (xForwardedForHeader != null) {
            String[] parts = xForwardedForHeader.split(COMMA);
            for (String part : parts) {
                headerValue.append(FOR).append(resolveIP(part.trim())).append(COMMA).append(" ");
            }
            headerValue.replace(headerValue.length() - 2, headerValue.length(), SEMI_COLON + " ");
            httpOutboundRequest.removeHeader(Constants.X_FORWARDED_FOR);
        }
        if (xForwardedByHeader != null) {
            headerValue.append(FOR).append(resolveIP(xForwardedByHeader.trim())).append(SEMI_COLON).append(" ");
            httpOutboundRequest.removeHeader(Constants.X_FORWARDED_BY);
        }
        headerValue.append(BY).append(resolveIP(localAddress));
        if (xForwardedHostHeader != null) {
            headerValue.append(SEMI_COLON + " " + HOST).append(xForwardedHostHeader);
            httpOutboundRequest.removeHeader(Constants.X_FORWARDED_HOST);
        }
        if (xForwardedProtoHeader != null) {
            headerValue.append(SEMI_COLON + " " + PROTO).append(xForwardedProtoHeader);
            httpOutboundRequest.removeHeader(Constants.X_FORWARDED_PROTO);
        }
        httpOutboundRequest.setHeader(Constants.FORWARDED, headerValue.toString());
    }
85397
public String getHeaderValue(String name) {
        if (headers == null) {
            return null;
        }
        return headers.get(name);
    }
1277467
public int getIntHeader(String name)
  {
    if (_header != null)
    {
      int headerVal = _header.getIntHeader(name);
      if (headerVal != -1)
        return headerVal;
    }
    if (this.headerTable != null)
    {
      int i = 0;
      for (Object obj : headerTable[0])
      {
        String strVal = (String) obj;
        if (name.equals(strVal))
        {
          return Integer.valueOf((String) headerTable[1].get(i));
        }
        i++;
      }
    }
    return -1;
  }
738832
def get_header(self, name, default=None):
        '''  '''
        return self._headers.get(_hkey(name), [default])[-1]
912550
public String getHeader(String header) {
        if (headers == null) {
            return null;
        }
        return headers.get(header);
    }
13685
public Optional<String> getHeader(String name) {
        PSequence<String> values = lowercaseHeaders.get(name.toLowerCase(Locale.ENGLISH));
        if (values == null || values.isEmpty()) {
            return Optional.empty();
        } else {
            return Optional.of(values.get(0));
        }
    }
757779
private String getSimpleHeaderValue(String header, HttpResponse httpResponse, boolean first) {
    if (StringUtils.isBlank(header)) {
      return StringUtils.EMPTY;
    }

    Header h;
    if (first) {
      h = httpResponse.getFirstHeader(header);
    } else {
      h = httpResponse.getLastHeader(header);
    }
    if (h == null) {
      return null;
    }
    return h.getValue();
  }
1271705
def getheader(self, header, default=None):
        '''
        
        '''
        if isinstance(header, str):
            return self.headers.get(header.lower(), default)
        return self.__rawheaders.get(header, default)
165765
function (requestV1) {
        if (_.isArray(requestV1.headers)) {
            return requestV1.headers;
        }

        var headers = [],
            traversed = {},
            headerData = requestV1.headerData || [],
            retainEmpty = this.options.retainEmptyValues;

        _.forEach(headerData, function (header) {
            if (_.startsWith(header.key, headersCommentPrefix) || (header.enabled === false)) {
                header.disabled = true;
                header.key = header.key.replace(headersCommentPrefix, '').trim();
            }

            // prevent empty header descriptions from showing up in converted results. This keeps the collections clean
            util.cleanEmptyValue(header, 'description', retainEmpty);

            delete header.enabled;
            headers.push(header); // @todo Improve this sequence to account for multi-valued headers

            traversed[header.key] = true;
        });

        // requestV1.headers is a string, so no descriptions can be obtained from it
        _.forEach(v1Common.parseHeaders(requestV1.headers), function (header) {
            !traversed[header.key] && headers.push(header);
        });

        return headers;
    }
1284437
def getheader(self, which, use_hash=None, polish=True):
        """"""
        header = getheader(
            which,
            use_hash=use_hash,
            target=self.target,
            no_tco=self.no_tco,
            strict=self.strict,
        )
        if polish:
            header = self.polish(header)
        return header
145096
def get_value(value):
    
    v = Value()
    if not value:
        raise errors.HeaderParseError("Expected value but found end of string")
    leader = None
    if value[0] in CFWS_LEADER:
        leader, value = get_cfws(value)
    if not value:
        raise errors.HeaderParseError("Expected value but found "
                                      "only {}".format(leader))
    if value[0] == '"':
        token, value = get_quoted_string(value)
    else:
        token, value = get_extended_attribute(value)
    if leader is not None:
        token[:0] = [leader]
    v.append(token)
    return v, value
656312
def use_forwarded_port(graph):
    
    # There must be a better way!
    context = _request_ctx_stack.top

    if _request_ctx_stack is None:
        return None

    # determine the configured overrides
    forwarded_host = graph.config.port_forwarding.get("host")
    forwarded_port = request.headers.get("X-Forwarded-Port")

    if not forwarded_port and not forwarded_host:
        return None

    # determine the current server name
    if ":" in context.url_adapter.server_name:
        server_host, server_port = context.url_adapter.server_name.split(":", 1)
    else:
        server_host = context.url_adapter.server_name
        server_port = 443 if context.url_adapter.url_scheme == "https" else 80

    # choose a new server name
    if forwarded_host:
        server_name = forwarded_host
    elif server_port:
        server_name = "{}:{}".format(server_host, forwarded_port)
    else:
        server_name = "{}:{}".format(server_host, server_port)

    context.url_adapter.server_name = server_name
    return server_name
278807
public String getHeader(String headerName) {
        List<String> headers = null;
        for (String h : headers().keySet()) {
            if (headerName.equalsIgnoreCase(h)) {
                headers = headers().get(h);
                break;
            }
        }
        if (headers == null || headers.isEmpty()) {
            return null;
        }
        return headers.get(0);
    }
171454
function (header) {
        if (!_.isString(header)) { return { key: E, value: E }; }

        var index = header.indexOf(HEADER_KV_SEPARATOR),
            key,
            value;

        (index < 0) && (index = header.length);

        key = header.substr(0, index);
        value = header.substr(index + 1);

        return {
            key: _.trim(key),
            value: _.trim(value)
        };
    }
37223
public void setForwardedHeader() {
        StringBuilder headerValue = new StringBuilder();
        if (forwardedHeader == null) {
            Object remoteAddressProperty = httpOutboundRequest.getProperty(Constants.REMOTE_ADDRESS);
            if (remoteAddressProperty != null) {
                String remoteAddress = ((InetSocketAddress) remoteAddressProperty).getAddress().getHostAddress();
                headerValue.append(FOR).append(resolveIP(remoteAddress)).append(SEMI_COLON).append(" ");
            }
            headerValue.append(BY).append(resolveIP(localAddress));
            Object hostHeader = httpOutboundRequest.getProperty(Constants.ORIGIN_HOST);
            if (hostHeader != null) {
                headerValue.append(SEMI_COLON + " " + HOST).append(hostHeader.toString());
            }
            Object protocolHeader = httpOutboundRequest.getProperty(Constants.PROTOCOL);
            if (protocolHeader != null) {
                headerValue.append(SEMI_COLON + " " + PROTO).append(protocolHeader.toString());
            }
            httpOutboundRequest.setHeader(Constants.FORWARDED, headerValue.toString());
            return;
        }
        String[] parts = forwardedHeader.split(SEMI_COLON);
        String previousForValue = null;
        String previousByValue = null;
        String previousHostValue = null;
        String previousProtoValue = null;
        for (String part : parts) {
            if (part.toLowerCase(Locale.getDefault()).contains(FOR)) {
                previousForValue = part.trim();
            } else if (part.toLowerCase(Locale.getDefault()).contains(BY)) {
                previousByValue = part.trim().substring(3);
            } else if (part.toLowerCase(Locale.getDefault()).contains(HOST)) {
                previousHostValue = part.substring(5);
            } else if (part.toLowerCase(Locale.getDefault()).contains(PROTO)) {
                previousProtoValue = part.substring(6);
            }
        }
        if (previousForValue == null) {
            previousForValue = previousByValue != null ? FOR + previousByValue : null;
        } else {
            previousForValue =
                    previousByValue == null ? previousForValue : previousForValue + COMMA + " " + FOR + previousByValue;
        }
        headerValue.append(previousForValue != null ? previousForValue + SEMI_COLON + " " : null);
        headerValue.append(BY).append(resolveIP(localAddress));

        if (previousHostValue != null) {
            headerValue.append(SEMI_COLON + " " + HOST).append(previousHostValue);
        }
        if (previousProtoValue != null) {
            headerValue.append(SEMI_COLON + " " + PROTO).append(previousProtoValue);
        }
        httpOutboundRequest.setHeader(Constants.FORWARDED, headerValue.toString());
    }