@Override public String path() { return this.delegate.path(); }
@Override public boolean test(ServerRequest request) { PathContainer pathContainer = request.pathContainer(); PathPattern.PathMatchInfo info = this.pattern.matchAndExtract(pathContainer); traceMatch("Pattern", this.pattern.getPatternString(), request.path(), info != null); if (info != null) { mergeAttributes(request, info.getUriVariables(), this.pattern); return true; } else { return false; } }
@Override public boolean test(ServerRequest request) { String pathExtension = UriUtils.extractFileExtension(request.path()); return this.extensionPredicate.test(pathExtension); }
/** * Get the request path as a {@code PathContainer}. */ default PathContainer pathContainer() { return PathContainer.parsePath(path()); }
@Test public void path() { String path = "/foo/bar"; when(mockRequest.path()).thenReturn(path); assertSame(path, wrapper.path()); }
@Override public Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) { Map<String, Object> errorAttributes = new LinkedHashMap<>(); errorAttributes.put("timestamp", new Date()); errorAttributes.put("path", request.path()); Throwable error = getError(request); HttpStatus errorStatus = determineHttpStatus(error); errorAttributes.put("status", errorStatus.value()); errorAttributes.put("error", errorStatus.getReasonPhrase()); errorAttributes.put("message", determineMessage(error)); handleException(errorAttributes, determineException(error), includeStackTrace); return errorAttributes; }
@Override public String path() { return this.request.path(); }
private String getBaseUrl(final ServerRequest request) { final URI uri = request.uri(); final int last = uri.toString().length() - request.path().length(); return uri.toString().substring(0, last); }
@Override public ServerRequest subRequest(ServerRequest request) { String requestPath = request.path(); String subPath = this.pathMatcher.extractPathWithinPattern(this.pattern, requestPath); return new SubPathServerRequestWrapper(request, subPath); } }
@Override public boolean test(ServerRequest request) { String path = request.path(); if (this.pathMatcher.match(this.pattern, path)) { if (request instanceof DefaultServerRequest) { DefaultServerRequest defaultRequest = (DefaultServerRequest) request; Map<String, String> uriTemplateVariables = this.pathMatcher.extractUriTemplateVariables(this.pattern, path); defaultRequest.exchange().getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables); } return true; } else { return false; } }
@Override public Mono<Resource> apply(ServerRequest request) { String path = processPath(request.path()); if (path.contains("%")) { path = UriUtils.decode(path, StandardCharsets.UTF_8); } if (!StringUtils.hasLength(path) || isInvalidPath(path)) { return Mono.empty(); } if (!PATH_MATCHER.match(this.pattern, path)) { return Mono.empty(); } else { path = PATH_MATCHER.extractPathWithinPattern(this.pattern, path); } try { Resource resource = this.location.createRelative(path); if (resource.exists() && resource.isReadable() && isResourceUnderLocation(resource)) { return Mono.just(resource); } else { return Mono.empty(); } } catch (IOException ex) { throw new UncheckedIOException(ex); } }