@Override protected void addFromRequest(final VariableSourceBuilder builder, final Request request) { addMavenCoordinates(builder, request.getPath()); }
@Override protected String getUrl(@Nonnull final Context context) { return context.getRequest().getPath().substring(1); } }
@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); // omit leading slash }
private String getRequestPath(final Context context) { return context.getRequest().getPath().substring(1); }
@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 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; } }
@Override public NegativeCacheKey getCacheKey(final Context context) { return new PathNegativeCacheKey(context.getRequest().getPath()); }
@Override public boolean matches(final Context context) { checkNotNull(context); String path = context.getRequest().getPath(); log.debug("Matching: {}~={}", path, pattern); final java.util.regex.Matcher m = pattern.matcher(path); if (m.matches()) { // expose match result in context context.getAttributes().set(State.class, new State() { @Override public MatchResult getMatchResult() { return m; } }); return true; } // no match return false; }
@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); } }
/** * 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 Response handle(Context context) throws Exception { String path = context.getRequest().getPath(); Matcher matcher = SNAPSHOT_PATH_PATTERN.matcher(path); if (!matcher.matches()) { context.getAttributes().set(AptSnapshotHandler.State.class, new AptSnapshotHandler.State(path.substring(1))); return context.proceed(); } String id = matcher.group(1); path = matcher.group(2); if (path.length() == 0) { return handleSnapshotAdminRequest(context, id); } else { return handleSnapshotFetchRequest(context, id, path); } }
@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 { String path = context.getRequest().getPath(); // sanity, to ensure we don't corrupt the path if (!path.endsWith("/")) { path = path + "/"; } for (String file : INDEX_FILES) { Response response = forward(context, path + file); // return response if it was successful or an error which was not not found if (response.getStatus().isSuccessful() || response.getStatus().getCode() != HttpStatus.NOT_FOUND) { return response; } // otherwise try next index file } // or there is no such file, give up not found return HttpResponses.notFound(context.getRequest().getPath()); }
@Override public boolean matches(final Context context) { checkNotNull(context); String path = context.getRequest().getPath(); log.debug("Matching: {}~={}", path, parser); final Map<String, String> tokens = parser.parse(path); if (tokens == null) { // There was no match. return false; } // matched expose tokens in context context.getAttributes().set(State.class, new State() { @Override public String pattern() { return pattern; } @Override public Map<String, String> getTokens() { return tokens; } }); return true; } }
public Builder copy(final Request request) { checkNotNull(request); attributes = request.getAttributes(); headers = request.getHeaders(); action = request.getAction(); path = request.getPath(); parameters = request.getParameters(); payload = request.getPayload(); multipart = request.isMultipart(); multiparts = request.getMultiparts(); return this; }
@Override public Response handle(final Context context) throws Exception { Response response = context.proceed(); try { if (isSuccessfulRequestWithContent(context, response)) { Repository repository = context.getRepository(); StorageFacet storageFacet = repository.facet(StorageFacet.class); Content content = (Content) response.getPayload(); AttributesMap attributes = content.getAttributes(); maybeUpdateLastDownloaded(storageFacet, attributes); } } catch (Exception e) { log.error("Failed to update last downloaded time for request {}", context.getRequest().getPath(), e); } return response; }
@Override public VariableSource fromRequest(final Request request, final Repository repository) { VariableSourceBuilder builder = new VariableSourceBuilder(); builder.addResolver(new ConstantVariableResolver(request.getPath(), PATH)); builder.addResolver(new ConstantVariableResolver(repository.getFormat().getValue(), FORMAT)); addFromRequest(builder, request); return builder.build(); }