MockHttpServletRequestBuilder allows for specifying content type as String value
Issue: SPR-12405
This commit is contained in:
@@ -186,11 +186,22 @@ public class MockHttpServletRequestBuilder
|
||||
|
||||
/**
|
||||
* Set the 'Content-Type' header of the request.
|
||||
* @param mediaType the content type
|
||||
* @param contentType the content type
|
||||
*/
|
||||
public MockHttpServletRequestBuilder contentType(MediaType mediaType) {
|
||||
Assert.notNull(mediaType, "'contentType' must not be null");
|
||||
this.contentType = mediaType.toString();
|
||||
public MockHttpServletRequestBuilder contentType(MediaType contentType) {
|
||||
Assert.notNull(contentType, "'contentType' must not be null");
|
||||
this.contentType = contentType.toString();
|
||||
this.headers.set("Content-Type", this.contentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 'Content-Type' header of the request.
|
||||
* @param contentType the content type
|
||||
* @since 4.1.2
|
||||
*/
|
||||
public MockHttpServletRequestBuilder contentType(String contentType) {
|
||||
this.contentType = MediaType.parseMediaType(contentType).toString();
|
||||
this.headers.set("Content-Type", this.contentType);
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user