private <T> ResponseEntity<T> createEntity(T body, HttpHeaders headers, int status) { HttpStatus resolvedStatus = HttpStatus.resolve(status); return resolvedStatus != null ? new ResponseEntity<>(body, headers, resolvedStatus) : ResponseEntity.status(status).headers(headers).body(body); }
private <T> ResponseEntity<T> createEntity(HttpHeaders headers, int status) { HttpStatus resolvedStatus = HttpStatus.resolve(status); return resolvedStatus != null ? new ResponseEntity<>(headers, resolvedStatus) : ResponseEntity.status(status).headers(headers).build(); }
@Override public String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } };
@Override public HttpHeaders getMultipartHeaders(String paramOrFileName) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(new MediaType("application", "octet-stream", StandardCharsets.ISO_8859_1)); return headers; } };
public ResponseEntity<String> handleHttpEntityWithCacheControl(HttpEntity<byte[]> httpEntity) throws Exception { String responseBody = "Handled requestBody=[" + new String(httpEntity.getBody(), "UTF-8") + "]"; return ResponseEntity.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).body(responseBody); }
@Override public String getContentType() { MediaType type = this.outputMessage.getHeaders().getContentType(); return (type != null ? type.toString() : null); }
/** * Set the {@literal Content-Disposition} header. * <p>This could be used on a response to indicate if the content is * expected to be displayed inline in the browser or as an attachment to be * saved locally. * <p>It can also be used for a {@code "multipart/form-data"} request. * For more details see notes on {@link #setContentDispositionFormData}. * @since 5.0 * @see #getContentDisposition() */ public void setContentDisposition(ContentDisposition contentDisposition) { set(CONTENT_DISPOSITION, contentDisposition.toString()); }
private static Charset getCharset(HttpHeaders headers) { Charset charset = (headers.getContentType() != null ? headers.getContentType().getCharset() : null); return (charset != null ? charset : DEFAULT_CHARSET); }
@Override public String getCharacterEncoding() { MediaType type = this.outputMessage.getHeaders().getContentType(); return (type != null && type.getCharset() != null ? type.getCharset().name() : null); }
/** * Return the list of acceptable {@linkplain MediaType media types}, * as specified by the {@code Accept} header. * <p>Returns an empty list when the acceptable media types are unspecified. */ public List<MediaType> getAccept() { return MediaType.parseMediaTypes(get(ACCEPT)); }
/** * Return a parsed representation of the {@literal Content-Disposition} header. * @since 5.0 * @see #setContentDisposition(ContentDisposition) */ public ContentDisposition getContentDisposition() { String contentDisposition = getFirst(CONTENT_DISPOSITION); if (contentDisposition != null) { return ContentDisposition.parse(contentDisposition); } return ContentDisposition.empty(); }
/** * Return the value of the {@code Range} header. * <p>Returns an empty list when the range is unknown. */ public List<HttpRange> getRange() { String value = getFirst(RANGE); return HttpRange.parseRanges(value); }
/** * Create a new builder with a {@linkplain HttpStatus#CREATED CREATED} status * and a location header set to the given URI. * @param location the location URI * @return the created builder * @since 4.1 */ public static BodyBuilder created(URI location) { BodyBuilder builder = status(HttpStatus.CREATED); return builder.location(location); }
/** * Set a configured {@link CacheControl} instance as the * new value of the {@code Cache-Control} header. * @since 5.0.5 */ public void setCacheControl(CacheControl cacheControl) { setOrRemove(CACHE_CONTROL, cacheControl.getHeaderValue()); }
@Override @Nullable public String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } };