Support headers in DataBinding via constructor args

Closes gh-34073
This commit is contained in:
rstoyanchev
2024-12-11 15:10:09 +00:00
parent 7b4e19c69b
commit 70c326ed30
4 changed files with 77 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ import reactor.core.publisher.Mono;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.support.WebExchangeDataBinder;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.server.ServerWebExchange;
@@ -57,7 +58,11 @@ public class ExtendedWebExchangeDataBinder extends WebExchangeDataBinder {
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
List<String> values = entry.getValue();
if (!CollectionUtils.isEmpty(values)) {
String name = entry.getKey().replace("-", "");
// For constructor args with @BindParam mapped to the actual header name
String name = entry.getKey();
addValueIfNotPresent(map, "Header", name, (values.size() == 1 ? values.get(0) : values));
// Also adapt to Java conventions for setters
name = StringUtils.uncapitalize(entry.getKey().replace("-", ""));
addValueIfNotPresent(map, "Header", name, (values.size() == 1 ? values.get(0) : values));
}
}