List of usage examples for org.springframework.http HttpMethod HEAD
HttpMethod HEAD
To view the source code for org.springframework.http HttpMethod HEAD.
Click Source Link
From source file:org.springframework.web.client.RestTemplate.java
public HttpHeaders headForHeaders(URI url) throws RestClientException { return execute(url, HttpMethod.HEAD, null, this.headersExtractor); }
From source file:org.springframework.web.client.RestTemplateIntegrationTests.java
@Test public void optionsForAllow() throws URISyntaxException { Set<HttpMethod> allowed = template.optionsForAllow(new URI(baseUrl + "/get")); assertEquals("Invalid response", EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD, HttpMethod.TRACE), allowed); }
From source file:org.springframework.web.reactive.function.server.RequestPredicates.java
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code HEAD} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is HEAD and if the given pattern * matches against the request path// w w w. jav a2 s .c om */ public static RequestPredicate HEAD(String pattern) { return method(HttpMethod.HEAD).and(path(pattern)); }
From source file:org.springframework.web.reactive.resource.ResourceWebHandler.java
/** * Processes a resource request.//from w ww . j ava2 s . c o m * <p>Checks for the existence of the requested resource in the configured list of locations. * If the resource does not exist, a {@code 404} response will be returned to the client. * If the resource exists, the request will be checked for the presence of the * {@code Last-Modified} header, and its value will be compared against the last-modified * timestamp of the given resource, returning a {@code 304} status code if the * {@code Last-Modified} value is greater. If the resource is newer than the * {@code Last-Modified} value, or the header is not present, the content resource * of the resource will be written to the response with caching headers * set to expire one year in the future. */ @Override public Mono<Void> handle(ServerWebExchange exchange) { return getResource(exchange).switchIfEmpty(Mono.defer(() -> { logger.trace("No matching resource found - returning 404"); return Mono.error(NOT_FOUND_EXCEPTION); })).flatMap(resource -> { try { if (HttpMethod.OPTIONS.matches(exchange.getRequest().getMethodValue())) { exchange.getResponse().getHeaders().add("Allow", "GET,HEAD,OPTIONS"); return Mono.empty(); } // Supported methods and required session HttpMethod httpMethod = exchange.getRequest().getMethod(); if (!SUPPORTED_METHODS.contains(httpMethod)) { return Mono.error(new MethodNotAllowedException(exchange.getRequest().getMethodValue(), SUPPORTED_METHODS)); } // Header phase if (exchange.checkNotModified(Instant.ofEpochMilli(resource.lastModified()))) { logger.trace("Resource not modified - returning 304"); return Mono.empty(); } // Apply cache settings, if any if (getCacheControl() != null) { String value = getCacheControl().getHeaderValue(); if (value != null) { exchange.getResponse().getHeaders().setCacheControl(value); } } // Check the media type for the resource MediaType mediaType = MediaTypeFactory.getMediaType(resource).orElse(null); if (mediaType != null) { if (logger.isTraceEnabled()) { logger.trace("Determined media type '" + mediaType + "' for " + resource); } } else { if (logger.isTraceEnabled()) { logger.trace("No media type found " + "for " + resource + " - not sending a content-type header"); } } // Content phase if (HttpMethod.HEAD.matches(exchange.getRequest().getMethodValue())) { setHeaders(exchange, resource, mediaType); exchange.getResponse().getHeaders().set(HttpHeaders.ACCEPT_RANGES, "bytes"); logger.trace("HEAD request - skipping content"); return Mono.empty(); } setHeaders(exchange, resource, mediaType); ResourceHttpMessageWriter writer = getResourceHttpMessageWriter(); Assert.state(writer != null, "No ResourceHttpMessageWriter"); return writer.write(Mono.just(resource), null, ResolvableType.forClass(Resource.class), mediaType, exchange.getRequest(), exchange.getResponse(), Collections.emptyMap()); } catch (IOException ex) { return Mono.error(ex); } }); }
From source file:org.springframework.web.servlet.resource.ResourceHttpRequestHandler.java
public ResourceHttpRequestHandler() { super(HttpMethod.GET.name(), HttpMethod.HEAD.name()); }