Search in sources :

Example 1 with EncoderConfig

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);
}
Also used : EncoderConfig(io.restassured.config.EncoderConfig) MediaType(org.springframework.http.MediaType)

Example 2 with EncoderConfig

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);
}
Also used : ObjectMapperSerializationContextImpl(io.restassured.internal.mapping.ObjectMapperSerializationContextImpl) ObjectMapperConfig(io.restassured.config.ObjectMapperConfig) EncoderConfig(io.restassured.config.EncoderConfig)

Example 3 with EncoderConfig

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;
}
Also used : EncoderConfig(io.restassured.config.EncoderConfig)

Aggregations

EncoderConfig (io.restassured.config.EncoderConfig)3 ObjectMapperConfig (io.restassured.config.ObjectMapperConfig)1 ObjectMapperSerializationContextImpl (io.restassured.internal.mapping.ObjectMapperSerializationContextImpl)1 MediaType (org.springframework.http.MediaType)1