Code optimization
This commit is contained in:
parent
48253e8027
commit
0c79379827
|
@ -34,6 +34,7 @@ import org.apache.hc.core5.function.Factory;
|
||||||
import org.apache.hc.core5.http.Header;
|
import org.apache.hc.core5.http.Header;
|
||||||
import org.apache.hc.core5.http.HttpHeaders;
|
import org.apache.hc.core5.http.HttpHeaders;
|
||||||
import org.apache.hc.core5.http.HttpRequest;
|
import org.apache.hc.core5.http.HttpRequest;
|
||||||
|
import org.apache.hc.core5.http.message.MessageSupport;
|
||||||
|
|
||||||
class ConditionalRequestBuilder<T extends HttpRequest> {
|
class ConditionalRequestBuilder<T extends HttpRequest> {
|
||||||
|
|
||||||
|
@ -85,19 +86,7 @@ class ConditionalRequestBuilder<T extends HttpRequest> {
|
||||||
*/
|
*/
|
||||||
public T buildConditionalRequestFromVariants(final T request, final Map<String, Variant> variants) {
|
public T buildConditionalRequestFromVariants(final T request, final Map<String, Variant> variants) {
|
||||||
final T newRequest = messageCopier.create(request);
|
final T newRequest = messageCopier.create(request);
|
||||||
|
newRequest.setHeader(MessageSupport.format(HttpHeaders.IF_NONE_MATCH, variants.keySet()));
|
||||||
// we do not support partial content so all etags are used
|
|
||||||
final StringBuilder etags = new StringBuilder();
|
|
||||||
boolean first = true;
|
|
||||||
for(final String etag : variants.keySet()) {
|
|
||||||
if (!first) {
|
|
||||||
etags.append(",");
|
|
||||||
}
|
|
||||||
first = false;
|
|
||||||
etags.append(etag);
|
|
||||||
}
|
|
||||||
|
|
||||||
newRequest.setHeader(HttpHeaders.IF_NONE_MATCH, etags.toString());
|
|
||||||
return newRequest;
|
return newRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue