Skip to content

Commit 5d67f2e

Browse files
authored
Core: Extend secondary cache support with optional security header (#159)
1 parent c880a77 commit 5d67f2e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main/java/org/prebid/cache/handlers/cache/PostCacheHandler.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.prebid.cache.routers.ApiConfig;
2828
import org.springframework.beans.factory.annotation.Autowired;
2929
import org.springframework.beans.factory.annotation.Value;
30+
import org.springframework.http.HttpHeaders;
3031
import org.springframework.http.HttpStatus;
3132
import org.springframework.http.MediaType;
3233
import org.springframework.stereotype.Component;
@@ -44,6 +45,7 @@
4445
import java.util.HashMap;
4546
import java.util.List;
4647
import java.util.Map;
48+
import java.util.function.Consumer;
4749
import java.util.function.Function;
4850

4951
@Component
@@ -210,6 +212,7 @@ private void sendRequestToSecondaryPrebidCacheHosts(List<PayloadWrapper> payload
210212
.uri(uriBuilder -> uriBuilder.path(config.getSecondaryCachePath())
211213
.queryParam("secondaryCache", "yes").build())
212214
.contentType(MediaType.APPLICATION_JSON)
215+
.headers(enrichWithSecurityHeader())
213216
.bodyValue(RequestObject.of(payloadTransfers))
214217
.exchange()
215218
.transform(CircuitBreakerOperator.of(circuitBreaker))
@@ -228,6 +231,13 @@ private void sendRequestToSecondaryPrebidCacheHosts(List<PayloadWrapper> payload
228231
}
229232
}
230233

234+
private Consumer<HttpHeaders> enrichWithSecurityHeader() {
235+
final String apiKey = apiConfig.getApiKey();
236+
return apiKey != null
237+
? httpHeaders -> httpHeaders.set(API_KEY_HEADER, apiKey)
238+
: httpHeaders -> { };
239+
}
240+
231241
private PayloadTransfer wrapperToTransfer(final PayloadWrapper wrapper) {
232242
return PayloadTransfer.builder().type(wrapper.getPayload().getType())
233243
.key(wrapper.getId()).value(wrapper.getPayload().getValue()).expiry(wrapper.getExpiry()).build();

0 commit comments

Comments
 (0)