Skip to content

Commit

Permalink
Make headers in ExecuteNexusOperationInput case insensitive (#2342)
Browse files Browse the repository at this point in the history
* Make headers in ExecuteNexusOperationInput case insensitive

* Ensure all headers sent are lower case

* run spotless
  • Loading branch information
Quinn-With-Two-Ns authored Dec 4, 2024
1 parent cbcf26c commit c7fcf12
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.*;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -285,7 +286,14 @@ public ExecuteNexusOperationInput(
this.resultType = resultType;
this.arg = arg;
this.options = options;
this.headers = headers;
this.headers =
headers.entrySet().stream()
.collect(
Collectors.toMap(
(k) -> k.getKey().toLowerCase(),
Map.Entry::getValue,
(a, b) -> a,
() -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)));
}

public String getService() {
Expand Down Expand Up @@ -316,6 +324,10 @@ public NexusOperationOptions getOptions() {
return options;
}

/**
* Get headers that will be sent with the request. The returned map operates without regard to
* case.
*/
public Map<String, String> getHeaders() {
return headers;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ public <R> ExecuteNexusOperationOutput<R> executeNexusOperation(
attributes.setOperation(input.getOperation());
attributes.setService(input.getService());
attributes.setEndpoint(input.getEndpoint());
attributes.putAllNexusHeader(input.getHeaders());
// Ensure that the headers are lowercase
input.getHeaders().forEach((k, v) -> attributes.putNexusHeader(k.toLowerCase(), v));
attributes.setScheduleToCloseTimeout(
ProtobufTimeUtils.toProtoDuration(input.getOptions().getScheduleToCloseTimeout()));

Expand Down

0 comments on commit c7fcf12

Please sign in to comment.