Skip to content

Commit

Permalink
"host" header breaking certain ingress controllers, its only used by …
Browse files Browse the repository at this point in the history
…APIM so remove it when APIM isn't used
  • Loading branch information
chtrembl committed Feb 9, 2024
1 parent 5ead9ee commit f18de8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
Expand All @@ -14,7 +16,14 @@
public class WebRequest implements Serializable {
private MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();

@Autowired
private ContainerEnvironment containerEnvironment;

public MultiValueMap<String, String> getHeaders() {
if(!StringUtils.isEmpty(this.containerEnvironment.getPetstoreAPIMHost()) && this.headers.get("host") == null)
{
this.headers.add("host", this.containerEnvironment.getPetstoreAPIMHost());
}
return this.headers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public Collection<Pet> getPets(String category) {
this.sessionUser.getCustomEventProperties(), null);
try {
Consumer<HttpHeaders> consumer = it -> it.addAll(this.webRequest.getHeaders());

pets = this.petServiceWebClient.get().uri("petstorepetservice/v2/pet/findByStatus?status=available")
.accept(MediaType.APPLICATION_JSON)
.headers(consumer)
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.header("host", this.containerEnvironment.getPetstoreAPIMHost())
.header("session-id", this.sessionUser.getSessionId())
.header("Ocp-Apim-Subscription-Key", this.containerEnvironment.getPetStoreServicesSubscriptionKey())
.header("Cache-Control", "no-cache").header("Ocp-Apim-Trace", "true").retrieve()
Expand Down Expand Up @@ -136,7 +136,6 @@ public Collection<Product> getProducts(String category, List<Tag> tags) {
.accept(MediaType.APPLICATION_JSON)
.headers(consumer)
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.header("host", this.containerEnvironment.getPetstoreAPIMHost())
.header("session-id", this.sessionUser.getSessionId())
.header("Ocp-Apim-Subscription-Key", this.containerEnvironment.getPetStoreServicesSubscriptionKey())
.header("Cache-Control", "no-cache").header("Ocp-Apim-Trace", "true").retrieve()
Expand Down Expand Up @@ -224,7 +223,6 @@ public void updateOrder(long productId, int quantity, boolean completeOrder) {
.accept(MediaType.APPLICATION_JSON)
.headers(consumer)
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.header("host", this.containerEnvironment.getPetstoreAPIMHost())
.header("session-id", this.sessionUser.getSessionId())
.header("Ocp-Apim-Subscription-Key", this.containerEnvironment.getPetStoreServicesSubscriptionKey())
.header("Cache-Control", "no-cache").header("Ocp-Apim-Trace", "true").retrieve()
Expand All @@ -251,7 +249,6 @@ public Order retrieveOrder(String orderId) {
.accept(MediaType.APPLICATION_JSON)
.headers(consumer)
.header("Content-Type", MediaType.APPLICATION_JSON_VALUE)
.header("host", this.containerEnvironment.getPetstoreAPIMHost())
.header("session-id", this.sessionUser.getSessionId())
.header("Ocp-Apim-Subscription-Key", this.containerEnvironment.getPetStoreServicesSubscriptionKey())
.header("Cache-Control", "no-cache").header("Ocp-Apim-Trace", "true").retrieve()
Expand Down

0 comments on commit f18de8d

Please sign in to comment.