Return content-type from saved request

This commit is contained in:
Jonas Bamberger 2023-06-30 11:47:11 +02:00 committed by Josh Cummings
parent 30d016bcbd
commit 07f737b989
2 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,7 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpHeaders;
/**
* Provides request parameters, headers and cookies from either an original request or a
@ -141,6 +142,11 @@ class SavedRequestAwareWrapper extends HttpServletRequestWrapper {
return this.savedRequest.getMethod();
}
@Override
public String getContentType() {
return getHeader(HttpHeaders.CONTENT_TYPE);
}
/**
* If the parameter is available from the wrapped request then the request has been
* forwarded/included to a URL with parameters, either supplementing or overriding the

View File

@ -24,6 +24,7 @@ import java.util.Locale;
import jakarta.servlet.http.Cookie;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.security.web.PortResolverImpl;
@ -169,4 +170,13 @@ public class SavedRequestAwareWrapperTests {
assertThat(wrapper.getIntHeader("nonexistent")).isEqualTo(-1);
}
@Test
public void correctContentTypeIsReturned() {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/notused");
request.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
SavedRequestAwareWrapper wrapper = createWrapper(request, new MockHttpServletRequest("GET", "/notused"));
assertThat(wrapper.getContentType()).isEqualTo(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
}
}