Skip to content

Commit

Permalink
Transform header name to property name using "camelCase", and use rep…
Browse files Browse the repository at this point in the history
…lace instead of replaceAll.
  • Loading branch information
remeio committed Jan 4, 2025
1 parent 57c0d95 commit efbdf84
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request)
String name = names.nextElement();
Object value = getHeaderValue(httpRequest, name);
if (value != null) {
name = StringUtils.uncapitalize(name.replace("-", ""));
name = transformedHeaderName(name);
addValueIfNotPresent(mpvs, "Header", name, value);
}
}
Expand All @@ -147,6 +147,10 @@ private static void addValueIfNotPresent(MutablePropertyValues mpvs, String labe
}
}

private static String transformedHeaderName(String headerName) {
return StringUtils.uncapitalize(headerName.replace("-", ""));
}

private @Nullable Object getHeaderValue(HttpServletRequest request, String name) {
if (!this.headerPredicate.test(name)) {
return null;
Expand Down Expand Up @@ -206,7 +210,7 @@ protected Set<String> initParameterNames(ServletRequest request) {
Enumeration<String> enumeration = httpServletRequest.getHeaderNames();
while (enumeration.hasMoreElements()) {
String headerName = enumeration.nextElement();
set.add(headerName.replaceAll("-", ""));
set.add(transformedHeaderName(headerName));
}
}
return set;
Expand Down

0 comments on commit efbdf84

Please sign in to comment.