Determines if the incoming request is sending content this route understands.

@param routeContext
@return true if the route handles the request accept/content-type
551728
protected boolean canConsume(RouteContext routeContext) {
        Set<String> contentTypes = getContentTypes(routeContext.getRequest());

        if (!declaredConsumes.isEmpty()) {
            if (declaredConsumes.contains(Consumes.ALL)) {
                log.debug("{} will handle Request because it consumes '{}'", LangUtils.toString(controllerMethod), Consumes.ALL);
                return true;
            }

            Set<String> types = new LinkedHashSet<>(contentTypes);
            if (types.isEmpty()) {
                // request does not specify a Content-Type so add Accept type(s)
                types.addAll(getAcceptTypes(routeContext.getRequest()));

                // request can handle any type, so consume the Request
                if (types.contains("*") || types.contains("*/*")) {
                    log.debug("{} will handle Request because it consumes '{}'", LangUtils.toString(controllerMethod), "*/*");
                    return true;
                }
            }

            for (String type : types) {
                if (declaredConsumes.contains(type)) {
                    // explicit content-type match
                    log.debug("{} will handle Request because it consumes '{}'", LangUtils.toString(controllerMethod), type);
                    return true;
                } else {
                    // look for a fuzzy content-type match
                    for (String declaredType : declaredConsumes) {
                        int fuzz = declaredType.indexOf('*');
                        if (fuzz > -1) {
                            String fuzzyType = declaredType.substring(0, fuzz);
                            if (type.startsWith(fuzzyType)) {
                                log.debug("{} will handle Request because it consumes '{}'", LangUtils.toString(controllerMethod), type);
                                return true;
                            }
                        }
                    }
                }
            }

            if (types.isEmpty()) {
                log.warn("{} can not handle Request because neither 'Accept' nor 'Content-Type' are set and Route @Consumes '{}'",
                    LangUtils.toString(controllerMethod), declaredConsumes);
            } else {
                log.warn("{} can not handle Request for '{}' because Route @Consumes '{}'", LangUtils.toString(controllerMethod),
                        types, declaredConsumes);
            }
            return false;
        }

        return true;
    }
306741
protected boolean moduleCanHandlePath( ModuleConfig moduleConfig, RequestProcessor rp, String servletPath )
    {
        if ( moduleConfig.getPrefix().equals( "" ) && servletPath.lastIndexOf( '/' ) > 0
             && rp instanceof PageFlowRequestProcessor )
        {
            return false;
        }
        
        return true;
    }
279144
public static boolean containsContentType(String contentType, String[] allowedContentTypes)
    {
        if (allowedContentTypes == null)
        {
            return false;
        }
        for (int i = 0; i < allowedContentTypes.length; i++)
        {
            if (allowedContentTypes[i].indexOf(contentType) != -1)
            {
                return true;
            }
        }
        return false;
    }
433041
public void checkContentType(final HttpServletRequest request) {
    String reqpar = request.getParameter(getContentTypeRequestName());

    if (reqpar != null) {
      if (reqpar.equals("!")) {
        // Go back to unsticky content type
        setContentTypeSticky(false);
      } else {
        setContentType(reqpar);
        setContentTypeSticky(false);
      }
    }

    reqpar = request.getParameter(getContentTypeStickyRequestName());
    if (reqpar != null) {
      if (reqpar.equals("!")) {
        // Go back to unsticky content type
        setContentTypeSticky(false);
      } else {
        setContentType(reqpar);
        setContentTypeSticky(true);
      }
    }
  }
197995
public static boolean isDelete(final WebContext context) {
        return HttpConstants.HTTP_METHOD.DELETE.name().equalsIgnoreCase(context.getRequestMethod());
    }
166095
public final boolean isValidEndContextForContentKind(SanitizedContentKind contentKind) {
    if (templateNestDepth != 0) {
      return false;
    }
    switch (contentKind) {
      case CSS:
        return state == HtmlContext.CSS && elType == ElementType.NONE;
      case HTML:
        return state == HtmlContext.HTML_PCDATA && elType == ElementType.NONE;
      case ATTRIBUTES:
        // Allow any html attribute context or html tag this. HTML_TAG is needed for constructs
        // like "checked" that don't require an attribute value. Explicitly disallow
        // HTML_NORMAL_ATTR_VALUE (e.g. foo={$x} without quotes) to help catch cases where
        // attributes aren't safely composable (e.g. foo={$x}checked would end up with one long
        // attribute value, whereas foo="{$x}"checked would be parsed as intended).
        return state == HtmlContext.HTML_ATTRIBUTE_NAME || state == HtmlContext.HTML_TAG;
      case JS:
        // Just ensure the state is JS -- don't worry about whether a regex is coming or not.
        return state == HtmlContext.JS && elType == ElementType.NONE;
      case URI:
        // Ensure that the URI content is non-empty and the URI type remains normal (which is
        // the assumed type of the URI content kind).
        return state == HtmlContext.URI && uriType == UriType.NORMAL && uriPart != UriPart.START;
      case TEXT:
        return state == HtmlContext.TEXT;
      case TRUSTED_RESOURCE_URI:
        // Ensure that the URI content is non-empty and the URI type remains normal (which is
        // the assumed type of the URI content kind).
        return state == HtmlContext.URI
            && uriType == UriType.TRUSTED_RESOURCE
            && uriPart != UriPart.START;
    }
    throw new IllegalArgumentException(
        "Specified content kind " + contentKind + " has no associated end context.");
  }
385400
public boolean isExclusion(String requestURI) {
        if (excludesPattern == null) {
            return false;
        }

        if (contextPath != null && requestURI.startsWith(contextPath)) {
            requestURI = requestURI.substring(contextPath.length());
            if (!requestURI.startsWith("/")) {
                requestURI = "/" + requestURI;
            }
        }

        for (String pattern : excludesPattern) {
            if (pathMatcher.matches(pattern, requestURI)) {
                return true;
            }
        }

        return false;
    }
878225
private void processFlash(RouteContext routeContext) {
        Flash flash = null;

        if (routeContext.hasSession()) {
            // get flash from session
            flash = routeContext.removeSession("flash");
            // put an empty flash (outgoing flash) in session; defense against session.get("flash")
            routeContext.setSession("flash", new Flash());
        }

        if (flash == null) {
            flash = new Flash();
        }

        // make current flash available to templates
        routeContext.setLocal("flash", flash);
    }
3736
public boolean checkSecurityConstraints(String pathInContext,
                                            HttpRequest request,
                                            HttpResponse response)
            throws HttpException, IOException
    {
        if (!super.checkSecurityConstraints(pathInContext,request,response) ||
            ! jSecurityCheck(pathInContext,request,response))
            return false;
        
        return true;
    }
1321372
private function checkRequest(ServerRequestInterface $request): bool
    {
        $contentType = $request->getHeaderLine('Content-Type');
        foreach ($this->contentType as $allowedType) {
            if (\stripos($contentType, $allowedType) === 0) {
                return true;
            }
        }
        return false;
    }
769794
protected function isSupportContentType(ServerRequestInterface $request): bool
    {
        $contentType = $request->getHeaderLine('content-type');

        foreach ($this->allowContentTypes as $allowContentType) {
            if (stripos($contentType, $allowContentType) === 0) {
                return true;
            }
        }

        return false;
    }
773080
public static boolean isPost(final WebContext context) {
        return HttpConstants.HTTP_METHOD.POST.name().equalsIgnoreCase(context.getRequestMethod());
    }
1005921
public static function post($route)
    {
        $content = self::traitPost($route);
        //
        self::addRoute($content);

        return true;
    }
1074294
private boolean isHtmlAcceptable(HttpServletRequest request)
	{
		@SuppressWarnings("unchecked") final List<String> accepts = ListUtility.list(ListUtility.iterate(request.getHeaders(
				HttpHeaderNames.ACCEPT)));

		for (String accept : accepts)
		{
			if (StringUtils.startsWithIgnoreCase(accept, "text/html"))
				return true;
		}

		return false;
	}
906772
public boolean execute(Context context) throws Exception
   {
      GenericWebAppContext webCtx = (GenericWebAppContext)context;
      HttpServletResponse response = webCtx.getResponse();
      HttpServletRequest request = webCtx.getRequest();

      // standalone request?
      String servletPath = request.getPathInfo();
      boolean doClose = true;
      // or included?
      if (servletPath == null)
      {
         servletPath = (String)request.getAttribute("javax.servlet.include.path_info");
         if (servletPath != null)
            doClose = false;
      }

      Node file = (Node)webCtx.getSession().getItem((String)context.get(pathKey));
      file.refresh(false);

      Node content = null;

      try
      {
         content = JCRCommandHelper.getNtResourceRecursively(file);
      }
      catch (ItemNotFoundException e)
      {
         // Patch for ver 1.0 back compatibility
         // as exo:image was not primary item
         if (file.isNodeType("exo:article"))
         {
            try
            {
               content = file.getNode("exo:image");
            }
            catch (PathNotFoundException e1)
            {
               throw e; // new ItemNotFoundException("No nt:resource node found at
               // "+file.getPath()+" nor primary items of nt:resource type
               // ");
            }
         }
         else
         {
            throw e; // new ItemNotFoundException("No nt:resource node found at
            // "+file.getPath()+" nor primary items of nt:resource type
            // ");
         }

      }

      // if(file.isNodeType("nt:file")) {
      // content = file.getNode("jcr:content");
      // } else if(file.isNodeType("exo:article")) {
      // content = file.getNode("exo:image");
      // } else
      // throw new Exception("Invalid node type, expected nt:file or exo:article,
      // have "+file.getPrimaryNodeType().getName()+" at "+file.getPath());

      Property data;
      try
      {
         data = content.getProperty("jcr:data");
      }
      catch (PathNotFoundException e)
      {
         throw new PathNotFoundException("No jcr:data node found at " + content.getPath());
      }

      String mime = content.getProperty("jcr:mimeType").getString();
      String encoding =
         content.hasProperty("jcr:encoding") ? content.getProperty("jcr:encoding").getString() : DEFAULT_ENCODING;

      MimeTypeResolver resolver = new MimeTypeResolver();
      String fileName = file.getName();
      String fileExt = "";
      if (fileName.lastIndexOf(".") > -1)
      {
         fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
         fileName = fileName.substring(0, fileName.lastIndexOf("."));
      }
      String mimeExt = resolver.getExtension(mime);
      if (fileExt == null || fileExt.length() == 0)
      {
         fileExt = mimeExt;
      }
      response.setContentType(mime + "; charset=" + encoding);
      String parameter = (String)context.get("cache-control-max-age");
      String cacheControl = parameter == null ? "" : "public, max-age=" + parameter;
      response.setHeader("Cache-Control: ", cacheControl);
      response.setHeader("Pragma: ", ""); // leave blank to avoid IE errors
      response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "." + fileExt + "\"");

      if (mime.startsWith("text"))
      {
         PrintWriter out = response.getWriter();
         out.write(data.getString());
         out.flush();
         if (doClose)
            out.close();
      }
      else
      {
         InputStream is = data.getStream();
         byte[] buf = new byte[is.available()];
         is.read(buf);
         ServletOutputStream os = response.getOutputStream();
         os.write(buf);
         os.flush();
         if (doClose)
            os.close();
      }

      return true;
   }
838586
boolean isEligible(Address address, @Nullable List<Route> routes) {
    // If this connection is not accepting new exchanges, we're done.
    if (transmitters.size() >= allocationLimit || noNewExchanges) return false;

    // If the non-host fields of the address don't overlap, we're done.
    if (!Internal.instance.equalsNonHost(this.route.address(), address)) return false;

    // If the host exactly matches, we're done: this connection can carry the address.
    if (address.url().host().equals(this.route().address().url().host())) {
      return true; // This connection is a perfect match.
    }

    // At this point we don't have a hostname match. But we still be able to carry the request if
    // our connection coalescing requirements are met. See also:
    // https://hpbn.co/optimizing-application-delivery/#eliminate-domain-sharding
    // https://daniel.haxx.se/blog/2016/08/18/http2-connection-coalescing/

    // 1. This connection must be HTTP/2.
    if (http2Connection == null) return false;

    // 2. The routes must share an IP address.
    if (routes == null || !routeMatchesAny(routes)) return false;

    // 3. This connection's server certificate's must cover the new host.
    if (address.hostnameVerifier() != OkHostnameVerifier.INSTANCE) return false;
    if (!supportsUrl(address.url())) return false;

    // 4. Certificate pinning must match the host.
    try {
      address.certificatePinner().check(address.url().host(), handshake().peerCertificates());
    } catch (SSLPeerUnverifiedException e) {
      return false;
    }

    return true; // The caller's address can be carried by this connection.
  }
1323008
protected boolean isGatewayPresent(final RequestContext context) {
        val requestParameterMap = context.getExternalContext().getRequestParameterMap();
        return StringUtils.hasText(requestParameterMap.get(CasProtocolConstants.PARAMETER_GATEWAY));
    }