Exemplo n.º 1
0
  /**
   * If there's no match, returns the result with {@link #notFound(Object) notFound} as the target
   * if it is set, otherwise returns {@code null}.
   */
  public RouteResult<T> route(final HttpMethod method, final String uri) {
    final QueryStringDecoder decoder = new QueryStringDecoder(uri);
    final String[] tokens = StringUtil.split(Path.removeSlashesAtBothEnds(decoder.path()), '/');

    MethodlessRouter<T> router = routers.get(method);
    if (router == null) {
      router = anyMethodRouter;
    }

    RouteResult<T> ret = router.route(tokens);
    if (ret != null) {
      return new RouteResult<T>(ret.target(), ret.pathParams(), decoder.parameters());
    }

    if (router != anyMethodRouter) {
      ret = anyMethodRouter.route(tokens);
      if (ret != null) {
        return new RouteResult<T>(ret.target(), ret.pathParams(), decoder.parameters());
      }
    }

    if (notFound != null) {
      // Return mutable map to be consistent, instead of
      // Collections.<String, String>emptyMap()
      return new RouteResult<T>(notFound, new HashMap<String, String>(), decoder.parameters());
    }

    return null;
  }
Exemplo n.º 2
0
 protected SpdyOrHttpChooser.SelectedProtocol getProtocol(SSLEngine var1) {
   String[] var2 = StringUtil.split(var1.getSession().getProtocol(), ':');
   if (var2.length < 2) {
     return SpdyOrHttpChooser.SelectedProtocol.HTTP_1_1;
   } else {
     SpdyOrHttpChooser.SelectedProtocol var3 =
         SpdyOrHttpChooser.SelectedProtocol.protocol(var2[1]);
     return var3;
   }
 }
Exemplo n.º 3
0
  /**
   * Returns allowed methods for a specific URI.
   *
   * <p>For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
   */
  public Set<HttpMethod> allowedMethods(final String uri) {
    final QueryStringDecoder decoder = new QueryStringDecoder(uri);
    final String[] tokens = StringUtil.split(Path.removeSlashesAtBothEnds(decoder.path()), '/');

    if (anyMethodRouter.anyMatched(tokens)) {
      return allAllowedMethods();
    }

    final Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
    for (Map.Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
      final MethodlessRouter<T> router = entry.getValue();
      if (router.anyMatched(tokens)) {
        final HttpMethod method = entry.getKey();
        ret.add(method);
      }
    }

    return ret;
  }