use of io.restassured.config.EncoderConfig in project rest-assured by rest-assured.
the class MockMvcRequestSenderImpl method setContentTypeToApplicationFormUrlEncoded.
private void setContentTypeToApplicationFormUrlEncoded(MockHttpServletRequestBuilder request) {
String contentType = APPLICATION_FORM_URLENCODED_VALUE;
EncoderConfig encoderConfig = config.getEncoderConfig();
if (encoderConfig.shouldAppendDefaultContentCharsetToContentTypeIfUndefined()) {
contentType += "; charset=";
if (encoderConfig.hasDefaultCharsetForContentType(contentType)) {
contentType += encoderConfig.defaultCharsetForContentType(contentType);
} else {
contentType += encoderConfig.defaultContentCharset();
}
}
MediaType mediaType = MediaType.parseMediaType(contentType);
request.contentType(mediaType);
List<Header> newHeaders = new ArrayList<Header>(headers.asList());
newHeaders.add(new Header(CONTENT_TYPE, mediaType.toString()));
headers = new Headers(newHeaders);
}
use of io.restassured.config.EncoderConfig in project rest-assured by rest-assured.
the class MultiPartSpecBuilder method applyContentToSpec.
private void applyContentToSpec(MultiPartSpecificationImpl spec) {
final Object actualContent;
if (explicitObjectMapper != null) {
ObjectMapperSerializationContextImpl ctx = new ObjectMapperSerializationContextImpl();
ctx.setObject(content);
ctx.setContentType(mimeType);
actualContent = explicitObjectMapper.serialize(ctx);
} else if (explicitObjectMapperType != null) {
actualContent = ObjectMapping.serialize(content, mimeType, null, explicitObjectMapperType, new ObjectMapperConfig(), new EncoderConfig());
} else {
actualContent = content;
}
spec.setContent(actualContent);
}
use of io.restassured.config.EncoderConfig in project rest-assured by rest-assured.
the class MockMvcRequestSenderImpl method findContentType.
// TODO Extract content-type from headers and apply charset if needed!
private String findContentType() {
String requestContentType = headers.getValue(CONTENT_TYPE);
if (StringUtils.isBlank(requestContentType) && !multiParts.isEmpty()) {
requestContentType = "multipart/" + config.getMultiPartConfig().defaultSubtype();
}
EncoderConfig encoderConfig = config.getEncoderConfig();
if (requestContentType != null && encoderConfig.shouldAppendDefaultContentCharsetToContentTypeIfUndefined() && !StringUtils.containsIgnoreCase(requestContentType, CHARSET)) {
// Append default charset to request content type
requestContentType += "; charset=";
if (encoderConfig.hasDefaultCharsetForContentType(requestContentType)) {
requestContentType += encoderConfig.defaultCharsetForContentType(requestContentType);
} else {
requestContentType += encoderConfig.defaultContentCharset();
}
}
return requestContentType;
}
Aggregations