mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Support header filtering in web data binding
Closes gh-34039
This commit is contained in:
+31
@@ -18,9 +18,11 @@ package org.springframework.web.servlet.mvc.method.annotation;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jakarta.servlet.ServletRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.web.bind.ServletRequestDataBinder;
|
||||
@@ -102,6 +104,22 @@ class ExtendedServletRequestDataBinderTests {
|
||||
assertThat(target.getAge()).isEqualTo(25);
|
||||
}
|
||||
|
||||
@Test
|
||||
void headerPredicate() {
|
||||
TestBinder binder = new TestBinder();
|
||||
binder.addHeaderPredicate(name -> !name.equalsIgnoreCase("Another-Int-Array"));
|
||||
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
||||
request.addHeader("Priority", "u1");
|
||||
request.addHeader("Some-Int-Array", "1");
|
||||
request.addHeader("Another-Int-Array", "1");
|
||||
|
||||
binder.addBindValues(mpvs, request);
|
||||
|
||||
assertThat(mpvs.size()).isEqualTo(1);
|
||||
assertThat(mpvs.get("someIntArray")).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void noUriTemplateVars() {
|
||||
TestBean target = new TestBean();
|
||||
@@ -116,4 +134,17 @@ class ExtendedServletRequestDataBinderTests {
|
||||
private record DataBean(String name, int age, @BindParam("Some-Int-Array") Integer[] someIntArray) {
|
||||
}
|
||||
|
||||
|
||||
private static class TestBinder extends ExtendedServletRequestDataBinder {
|
||||
|
||||
public TestBinder() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindValues(MutablePropertyValues mpvs, ServletRequest request) {
|
||||
super.addBindValues(mpvs, request);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user