Code optimization

This commit is contained in:
Oleg Kalnichevski 2023-06-18 17:14:53 +02:00
parent 48253e8027
commit 0c79379827
1 changed files with 2 additions and 13 deletions

View File

@ -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;
} }