/** * Path + query parameters provide a unique enough request key for known formats. * If a format needs to add more context then they should customize this method. * * @return key that uniquely identifies this upstream request from other contexts * * @since 3.4 */ protected String getRequestKey(final Context context) { return context.getRequest().getPath() + '?' + context.getRequest().getParameters(); }
@Override public boolean matches(final Context context) { final String action = context.getRequest().getAction(); return allowedActions.contains(action); } }
/** * Returns all responses from all members as a linked map, where order is group member order. */ protected LinkedHashMap<Repository, Response> getAll(@Nonnull final Context context, @Nonnull final Iterable<Repository> members, @Nonnull final DispatchedRepositories dispatched) throws Exception { return getAll(context.getRequest(), context, members, dispatched); }
@Override public boolean matches(final Context context) { checkNotNull(context); String path = context.getRequest().getPath(); log.debug("Matching: {}={} ignore-case: {}", path, literal, ignoreCase); if (ignoreCase) { return path.equalsIgnoreCase(literal); } else { return path.equals(literal); } }
@Override protected String getUrl(@Nonnull final Context context) { return context.getRequest().getPath().substring(1); } }
private boolean isGetOrHeadRequest(final Context context) { String action = context.getRequest().getAction(); return GET.equals(action) || HEAD.equals(action); }
@Override public boolean matches(final Context context) { checkNotNull(context); String action = context.getRequest().getAction(); String path = context.getRequest().getPath(); log.debug("Matching: {} {}", action, path); if (HttpMethods.GET.equals(action)) { path = Strings2.lower(path); return path.endsWith("/") || path.endsWith("/index.html") || path.endsWith("/index.htm"); } return false; } }
/** * Builds a not-allowed response if the specified method is unsupported under the specified context, null otherwise. */ @Nullable protected Response buildMethodNotAllowedResponse(final Context context) { final String action = context.getRequest().getAction(); if (!GET.equals(action) && !HEAD.equals(action)) { return HttpResponses.methodNotAllowed(action, GET, HEAD); } return null; }
@Override public boolean matches(final Context context) { checkNotNull(context); String path = context.getRequest().getPath(); log.debug("Matching: {} starts-with={} ignore-case: {}", path, prefix, ignoreCase); if (ignoreCase) { return Strings2.lower(path).startsWith(Strings2.lower(prefix)); } else { return path.startsWith(prefix); } }
@Override public boolean matches(final Context context) { checkNotNull(context); String path = context.getRequest().getPath(); log.debug("Matching: {} ends-with={} ignore-case: {}", path, suffix, ignoreCase); if (ignoreCase) { return Strings2.lower(path).endsWith(Strings2.lower(suffix)); } else { return path.endsWith(suffix); } }
@Override public NegativeCacheKey getCacheKey(final Context context) { return new PathNegativeCacheKey(context.getRequest().getPath()); }
@Override protected String getUrl(@Nonnull final Context context) { AssetKind assetKind = context.getAttributes().require(AssetKind.class); switch (assetKind) { case ZIPBALL: return getZipballUrl(context); default: return context.getRequest().getPath().substring(1); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Repository repository = context.getRepository(); Parameters parameters = context.getRequest().getParameters(); log.debug("[searchV1] repository: {} parameters: {}", repository.getName(), parameters); return NpmResponses.ok(repository.facet(NpmSearchFacet.class).searchV1(parameters)); } };
@Override public boolean matches(final Context context) { final String path = context.getRequest().getPath(); if (predicate.apply(path)) { final MavenPath mavenPath = mavenPathParser.parsePath(path); context.getAttributes().set(MavenPath.class, mavenPath); return true; } return false; } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Repository repository = context.getRepository(); Parameters parameters = context.getRequest().getParameters(); log.debug("[searchIndex] repository: {} parameters: {}", repository.getName(), parameters); return NpmResponses.ok(repository.facet(NpmSearchIndexFacet.class).searchIndex(indexSince(parameters))); } };
@Override public Response handle(Context context) throws Exception { String path = assetPath(context); String method = context.getRequest().getAction(); AptSigningFacet facet = context.getRepository().facet(AptSigningFacet.class); if ("repository-key.gpg".equals(path) && GET.equals(method)) { return HttpResponses.ok(facet.getPublicKey()); } return context.proceed(); }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { State state = context.getAttributes().require(TokenMatcher.State.class); Repository repository = context.getRepository(); log.debug("[putPackage] repository: {} tokens: {}", repository.getName(), state.getTokens()); repository.facet(NpmHostedFacet.class) .putPackage(packageId(state), revision(state), context.getRequest().getPayload()); return NpmResponses.ok(); } };
private Response forward(final Context context, final String path) throws Exception { log.trace("Forwarding request to path: {}", path); Request request = new Request.Builder() .copy(context.getRequest()) .path(path) .build(); return context.getRepository() .facet(ViewFacet.class) .dispatch(request); } }
@Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { SecurityFacet securityFacet = context.getRepository().facet(SecurityFacet.class); //we employ the model that one security check per request is all that is necessary, if this handler is in a nested //repository (because this is a group repository), there is no need to check authz again if (context.getAttributes().get(AUTHORIZED_KEY) == null) { securityFacet.ensurePermitted(context.getRequest()); context.getAttributes().set(AUTHORIZED_KEY, true); } return context.proceed(); } }
private Response doPut(@Nonnull final Context context, final MavenPath path, final MavenFacet mavenFacet) throws IOException { if (mavenFacet.layoutPolicy() == LayoutPolicy.STRICT && isValidSnapshot(path.getCoordinates()) && !mavenFacet.getMavenPathParser().isRepositoryMetadata(path)) { throw new IllegalOperationException("Invalid path for a Maven 2 repository"); } mavenFacet.put(path, context.getRequest().getPayload()); return HttpResponses.created(); }