@Override public boolean test(ServerRequest request) { String pathExtension = UriUtils.extractFileExtension(request.path()); return this.extensionPredicate.test(pathExtension); }
@Override @Nullable protected String getMediaTypeKey(NativeWebRequest webRequest) { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request == null) { return null; } String path = this.urlPathHelper.getLookupPathForRequest(request); String extension = UriUtils.extractFileExtension(path); return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null); }
/** * Remove any path extension from the {@link HttpServletRequest#getRequestURI() * requestURI}. This method must be invoked before any calls to {@link #path(String)} * or {@link #pathSegment(String...)}. * <pre> * GET http://foo.com/rest/books/6.json * * ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request); * String ext = builder.removePathExtension(); * String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString(); * assertEquals("http://foo.com/rest/books/6/pages/1.json", result); * </pre> * @return the removed path extension for possible re-use, or {@code null} * @since 4.0 */ @Nullable public String removePathExtension() { String extension = null; if (this.originalPath != null) { extension = UriUtils.extractFileExtension(this.originalPath); if (!StringUtils.isEmpty(extension)) { int end = this.originalPath.length() - (extension.length() + 1); replacePath(this.originalPath.substring(0, end)); } this.originalPath = null; } return extension; }
@Override @Nullable protected String getMediaTypeKey(NativeWebRequest webRequest) { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request == null) { return null; } String path = this.urlPathHelper.getLookupPathForRequest(request); String extension = UriUtils.extractFileExtension(path); return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null); }
/** * Remove any path extension from the {@link HttpServletRequest#getRequestURI() * requestURI}. This method must be invoked before any calls to {@link #path(String)} * or {@link #pathSegment(String...)}. * <pre> * GET http://foo.com/rest/books/6.json * * ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request); * String ext = builder.removePathExtension(); * String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString(); * assertEquals("http://foo.com/rest/books/6/pages/1.json", result); * </pre> * @return the removed path extension for possible re-use, or {@code null} * @since 4.0 */ @Nullable public String removePathExtension() { String extension = null; if (this.originalPath != null) { extension = UriUtils.extractFileExtension(this.originalPath); if (!StringUtils.isEmpty(extension)) { int end = this.originalPath.length() - (extension.length() + 1); replacePath(this.originalPath.substring(0, end)); } this.originalPath = null; } return extension; }
@Test public void extractFileExtension() { assertEquals("html", UriUtils.extractFileExtension("index.html")); assertEquals("html", UriUtils.extractFileExtension("/index.html")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html#/a")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html#/path/a")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html#/path/a.do")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html#aaa?bbb")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html#aaa.xml?bbb")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=a")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=/path/a")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=/path/a.do")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=/path/a#/path/a")); assertEquals("html", UriUtils.extractFileExtension("/products/view.html?param=/path/a.do#/path/a.do")); assertEquals("html", UriUtils.extractFileExtension("/products;q=11/view.html?param=/path/a.do")); assertEquals("html", UriUtils.extractFileExtension("/products;q=11/view.html;r=22?param=/path/a.do")); assertEquals("html", UriUtils.extractFileExtension("/products;q=11/view.html;r=22;s=33?param=/path/a.do")); }
@Override protected String extractKey(ServerWebExchange exchange) { String path = exchange.getRequest().getURI().getRawPath(); String extension = UriUtils.extractFileExtension(path); return (StringUtils.hasText(extension)) ? extension.toLowerCase(Locale.ENGLISH) : null; }
@Override @Nullable protected String getMediaTypeKey(NativeWebRequest webRequest) { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request == null) { logger.warn("An HttpServletRequest is required to determine the media type key"); return null; } String path = this.urlPathHelper.getLookupPathForRequest(request); String extension = UriUtils.extractFileExtension(path); return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null); }
/** * Remove any path extension from the {@link HttpServletRequest#getRequestURI() * requestURI}. This method must be invoked before any calls to {@link #path(String)} * or {@link #pathSegment(String...)}. * <pre> * GET http://foo.com/rest/books/6.json * * ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request); * String ext = builder.removePathExtension(); * String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString(); * assertEquals("http://foo.com/rest/books/6/pages/1.json", result); * </pre> * @return the removed path extension for possible re-use, or {@code null} * @since 4.0 */ public String removePathExtension() { String extension = null; if (this.originalPath != null) { extension = UriUtils.extractFileExtension(this.originalPath); if (!StringUtils.isEmpty(extension)) { int end = this.originalPath.length() - (extension.length() + 1); replacePath(this.originalPath.substring(0, end)); } this.originalPath = null; } return extension; }
@Override @Nullable protected String getMediaTypeKey(NativeWebRequest webRequest) { HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); if (request == null) { return null; } String path = this.urlPathHelper.getLookupPathForRequest(request); String extension = UriUtils.extractFileExtension(path); return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null); }