Skip to content

Commit

Permalink
Add case insensitive behavior to header condition based throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
rmsamitha committed Jul 15, 2024
1 parent db3437b commit 91f127a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ public void setDataReference(String applicationLevelThrottleKey, String applicat
Map<String, String> transportHeaderMap = (Map<String, String>) axis2MessageContext
.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (transportHeaderMap != null) {
this.headersMap = new HashMap<>(transportHeaderMap);
// convert all transport headers to lower case in order to make the header condition based throttling
// case-insensitive
Map<String, String> lowerCaseTransportHeaderMap = new HashMap<>();
for (Map.Entry<String, String> entry : transportHeaderMap.entrySet()) {
lowerCaseTransportHeaderMap.put(entry.getKey().toLowerCase(), String.valueOf(entry.getValue()));
}
this.headersMap = new HashMap<>(lowerCaseTransportHeaderMap);
}

if (messageContext.getProperty(APIThrottleConstants.CUSTOM_PROPERTY) != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ private static String getPolicyCondition(Set<Condition> conditions) {
StringBuilder conditionString = new StringBuilder();
int i = 0;
for (Condition condition : conditions) {
if ("Header".equals(
condition.getConditionType())) {
// set the header name of header based conditions, to lower case to make the condition case-insensitive
condition.setName(condition.getName().toLowerCase(Locale.ENGLISH));
}
org.wso2.carbon.apimgt.api.model.policy.Condition mappedCondition =
PolicyMappingUtil.mapCondition(condition);
if (i == 0) {
Expand Down

0 comments on commit 91f127a

Please sign in to comment.