Polishing

This commit is contained in:
Juergen Hoeller
2018-06-28 18:13:40 +02:00
parent 03beee7b68
commit 9a20ec9284
6 changed files with 32 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -177,9 +177,9 @@ public class ContentDisposition {
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0);
result = 31 * result + (modificationDate != null ? modificationDate.hashCode() : 0);
result = 31 * result + (readDate != null ? readDate.hashCode() : 0);
result = 31 * result + (this.creationDate != null ? this.creationDate.hashCode() : 0);
result = 31 * result + (this.modificationDate != null ? this.modificationDate.hashCode() : 0);
result = 31 * result + (this.readDate != null ? this.readDate.hashCode() : 0);
return result;
}
@@ -198,7 +198,7 @@ public class ContentDisposition {
sb.append(this.name).append('\"');
}
if (this.filename != null) {
if(this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
if (this.charset == null || StandardCharsets.US_ASCII.equals(this.charset)) {
sb.append("; filename=\"");
sb.append(this.filename).append('\"');
}
@@ -441,12 +441,12 @@ public class ContentDisposition {
public interface Builder {
/**
* Set the value of the {@literal name} parameter
* Set the value of the {@literal name} parameter.
*/
Builder name(String name);
/**
* Set the value of the {@literal filename} parameter
* Set the value of the {@literal filename} parameter.
*/
Builder filename(String filename);
@@ -463,7 +463,7 @@ public class ContentDisposition {
Builder filename(String filename, Charset charset);
/**
* Set the value of the {@literal size} parameter
* Set the value of the {@literal size} parameter.
*/
Builder size(Long size);
@@ -483,7 +483,7 @@ public class ContentDisposition {
Builder readDate(ZonedDateTime readDate);
/**
* Build the content disposition
* Build the content disposition.
*/
ContentDisposition build();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
}
}
catch (IOException ex) {
logger.trace("No gzipped resource for [" + resource.getFilename() + "]", ex);
logger.trace("No gzip resource for [" + resource.getFilename() + "]", ex);
}
}
return resource;
@@ -77,6 +77,9 @@ public class GzipResourceResolver extends AbstractResourceResolver {
}
/**
* A gzipped {@link HttpResource}.
*/
static final class GzippedResource extends AbstractResource implements HttpResource {
private final Resource original;
@@ -156,13 +159,8 @@ public class GzipResourceResolver extends AbstractResourceResolver {
@Override
public HttpHeaders getResponseHeaders() {
HttpHeaders headers;
if(this.original instanceof HttpResource) {
headers = ((HttpResource) this.original).getResponseHeaders();
}
else {
headers = new HttpHeaders();
}
HttpHeaders headers = (this.original instanceof HttpResource ?
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
return headers;
}

View File

@@ -323,23 +323,18 @@ public class VersionResourceResolver extends AbstractResourceResolver {
@Override
public String getDescription() {
return original.getDescription();
return this.original.getDescription();
}
@Override
public InputStream getInputStream() throws IOException {
return original.getInputStream();
return this.original.getInputStream();
}
@Override
public HttpHeaders getResponseHeaders() {
HttpHeaders headers;
if(this.original instanceof HttpResource) {
headers = ((HttpResource) this.original).getResponseHeaders();
}
else {
headers = new HttpHeaders();
}
HttpHeaders headers = (this.original instanceof HttpResource ?
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
headers.setETag("\"" + this.version + "\"");
return headers;
}

View File

@@ -153,14 +153,13 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
HttpHeaders entityHeaders = httpEntity.getHeaders();
HttpHeaders responseHeaders = exchange.getResponse().getHeaders();
if (!entityHeaders.isEmpty()) {
entityHeaders.entrySet().stream()
.filter(entry -> !responseHeaders.containsKey(entry.getKey()))
.forEach(entry -> responseHeaders.put(entry.getKey(), entry.getValue()));
}
if(httpEntity.getBody() == null || returnValue instanceof HttpHeaders) {
if (httpEntity.getBody() == null || returnValue instanceof HttpHeaders) {
return exchange.getResponse().setComplete();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ public class GzipResourceResolver extends AbstractResourceResolver {
}
}
catch (IOException ex) {
logger.trace("No gzipped resource for [" + resource.getFilename() + "]", ex);
logger.trace("No gzip resource for [" + resource.getFilename() + "]", ex);
}
return resource;
@@ -78,6 +78,9 @@ public class GzipResourceResolver extends AbstractResourceResolver {
}
/**
* A gzipped {@link HttpResource}.
*/
static final class GzippedResource extends AbstractResource implements HttpResource {
private final Resource original;
@@ -157,13 +160,8 @@ public class GzipResourceResolver extends AbstractResourceResolver {
@Override
public HttpHeaders getResponseHeaders() {
HttpHeaders headers;
if (this.original instanceof HttpResource) {
headers = ((HttpResource) this.original).getResponseHeaders();
}
else {
headers = new HttpHeaders();
}
HttpHeaders headers = (this.original instanceof HttpResource ?
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
return headers;
}

View File

@@ -316,23 +316,18 @@ public class VersionResourceResolver extends AbstractResourceResolver {
@Override
public String getDescription() {
return original.getDescription();
return this.original.getDescription();
}
@Override
public InputStream getInputStream() throws IOException {
return original.getInputStream();
return this.original.getInputStream();
}
@Override
public HttpHeaders getResponseHeaders() {
HttpHeaders headers;
if (this.original instanceof HttpResource) {
headers = ((HttpResource) this.original).getResponseHeaders();
}
else {
headers = new HttpHeaders();
}
HttpHeaders headers = (this.original instanceof HttpResource ?
((HttpResource) this.original).getResponseHeaders() : new HttpHeaders());
headers.setETag("\"" + this.version + "\"");
return headers;
}