Skip to content

Commit

Permalink
Merge pull request #3500 from renuka-fernando/set-api-uuid-header
Browse files Browse the repository at this point in the history
Send API UUID to the backend as a header
  • Loading branch information
renuka-fernando authored Apr 18, 2024
2 parents 10e5e6f + 4c58759 commit 152ed10
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class APIConstants {
public static final String CONTENT_TYPE_HEADER = "Content-type";
public static final String APPLICATION_JSON = "application/json";
public static final String API_TRACE_KEY = "X-TRACE-KEY";
public static final String CHOREO_API_ID_HEADER = "X-Choreo-API-ID";
public static final String X_FORWARDED_FOR = "x-forwarded-for";
public static final String PATH_HEADER = ":path";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ private CheckResponse buildResponse(CheckRequest request, ResponseObject respons
.setHeader(HeaderValue.newBuilder().setKey(APIConstants.API_TRACE_KEY).setValue(traceKey).build())
.build();
okResponseBuilder.addHeaders(headerValueOption);

// Add the API UUID to the request headers tobe sent to the backend
headerValueOption = HeaderValueOption.newBuilder()
.setHeader(HeaderValue.newBuilder().setKey(APIConstants.CHOREO_API_ID_HEADER)
.setValue(responseObject.getApiUuid()).build()).build();
okResponseBuilder.addHeaders(headerValueOption);

return CheckResponse.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build())
.setOkResponse(okResponseBuilder.build())
.setDynamicMetadata(structBuilder.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void checkHeadersSentToBackend() throws Exception {

// Request headers received by the backend
JSONObject headersSentToBackend = new JSONObject(response.getData());
Assert.assertEquals(headersSentToBackend.length(), 8, "Unexpected number of headers received by the backend");
Assert.assertEquals(headersSentToBackend.length(), 9, "Unexpected number of headers received by the backend");

JSONObject headersToBackend = Utils.changeHeadersToLowerCase(headersSentToBackend);

Expand All @@ -63,6 +63,7 @@ public void checkHeadersSentToBackend() throws Exception {
Assert.assertNotNull(headersToBackend.get("pragma"));
Assert.assertNotNull(headersToBackend.get("user-agent"));
Assert.assertNotNull(headersToBackend.get("cache-control"));
Assert.assertNotNull(headersToBackend.get("x-choreo-api-id"));

Assert.assertFalse(headersToBackend.has("x-envoy-original-path"), "x-envoy-original-path not removed");
Assert.assertFalse(headersToBackend.has("x-wso2-cluster-header"), "x-wso2-cluster-header not removed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void checkHeadersSentToBackend() throws Exception {

// Request headers received by the backend
JSONObject headersSentToBackend = new JSONObject(response.getData());
Assert.assertEquals(headersSentToBackend.length(), 9, "Unexpected number of headers received by the backend");
Assert.assertEquals(headersSentToBackend.length(), 10, "Unexpected number of headers received by the backend");

JSONObject headersToBackend = Utils.changeHeadersToLowerCase(headersSentToBackend);

Expand All @@ -74,6 +74,7 @@ public void checkHeadersSentToBackend() throws Exception {
Assert.assertNotNull(headersToBackend.get("pragma"));
Assert.assertNotNull(headersToBackend.get("user-agent"));
Assert.assertNotNull(headersToBackend.get("cache-control"));
Assert.assertNotNull(headersToBackend.get("x-choreo-api-id"));

Assert.assertFalse(headersToBackend.has("x-envoy-original-path"), "x-envoy-original-path not removed");
Assert.assertFalse(headersToBackend.has("x-wso2-cluster-header"), "x-wso2-cluster-header not removed");
Expand Down

0 comments on commit 152ed10

Please sign in to comment.