Search in sources :

Example 1 with LinkedCaseInsensitiveMap

use of cn.taketoday.util.LinkedCaseInsensitiveMap in project today-infrastructure by TAKETODAY.

the class ServletServerHttpRequest method initHeaders.

private static MultiValueMap<String, String> initHeaders(MultiValueMap<String, String> headerValues, HttpServletRequest request) {
    HttpHeaders headers = null;
    MediaType contentType = null;
    if (StringUtils.isEmpty(headerValues.getFirst(HttpHeaders.CONTENT_TYPE))) {
        String requestContentType = request.getContentType();
        if (StringUtils.isNotEmpty(requestContentType)) {
            contentType = MediaType.parseMediaType(requestContentType);
            headers = new DefaultHttpHeaders(headerValues);
            headers.setContentType(contentType);
        }
    }
    if (contentType != null && contentType.getCharset() == null) {
        String encoding = request.getCharacterEncoding();
        if (StringUtils.isNotEmpty(encoding)) {
            Map<String, String> params = new LinkedCaseInsensitiveMap<>();
            params.putAll(contentType.getParameters());
            params.put("charset", Charset.forName(encoding).toString());
            headers.setContentType(new MediaType(contentType, params));
        }
    }
    if (headerValues.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
        int contentLength = request.getContentLength();
        if (contentLength != -1) {
            headers = (headers != null ? headers : new DefaultHttpHeaders(headerValues));
            headers.setContentLength(contentLength);
        }
    }
    return (headers != null ? headers : headerValues);
}
Also used : HttpHeaders(cn.taketoday.http.HttpHeaders) DefaultHttpHeaders(cn.taketoday.http.DefaultHttpHeaders) LinkedCaseInsensitiveMap(cn.taketoday.util.LinkedCaseInsensitiveMap) DefaultHttpHeaders(cn.taketoday.http.DefaultHttpHeaders) MediaType(cn.taketoday.http.MediaType)

Example 2 with LinkedCaseInsensitiveMap

use of cn.taketoday.util.LinkedCaseInsensitiveMap in project today-infrastructure by TAKETODAY.

the class UtilNamespaceHandlerTests method testMapWithTypes.

@Test
public void testMapWithTypes() {
    Map map = (Map) this.beanFactory.getBean("mapWithTypes");
    boolean condition = map instanceof LinkedCaseInsensitiveMap;
    assertThat(condition).isTrue();
    assertThat(map.get("bean")).isEqualTo(this.beanFactory.getBean("testBean"));
}
Also used : LinkedCaseInsensitiveMap(cn.taketoday.util.LinkedCaseInsensitiveMap) LinkedCaseInsensitiveMap(cn.taketoday.util.LinkedCaseInsensitiveMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with LinkedCaseInsensitiveMap

use of cn.taketoday.util.LinkedCaseInsensitiveMap in project today-framework by TAKETODAY.

the class ServletServerHttpRequest method initHeaders.

private static MultiValueMap<String, String> initHeaders(MultiValueMap<String, String> headerValues, HttpServletRequest request) {
    HttpHeaders headers = null;
    MediaType contentType = null;
    if (StringUtils.isEmpty(headerValues.getFirst(HttpHeaders.CONTENT_TYPE))) {
        String requestContentType = request.getContentType();
        if (StringUtils.isNotEmpty(requestContentType)) {
            contentType = MediaType.parseMediaType(requestContentType);
            headers = new DefaultHttpHeaders(headerValues);
            headers.setContentType(contentType);
        }
    }
    if (contentType != null && contentType.getCharset() == null) {
        String encoding = request.getCharacterEncoding();
        if (StringUtils.isNotEmpty(encoding)) {
            Map<String, String> params = new LinkedCaseInsensitiveMap<>();
            params.putAll(contentType.getParameters());
            params.put("charset", Charset.forName(encoding).toString());
            headers.setContentType(new MediaType(contentType, params));
        }
    }
    if (headerValues.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
        int contentLength = request.getContentLength();
        if (contentLength != -1) {
            headers = (headers != null ? headers : new DefaultHttpHeaders(headerValues));
            headers.setContentLength(contentLength);
        }
    }
    return (headers != null ? headers : headerValues);
}
Also used : HttpHeaders(cn.taketoday.http.HttpHeaders) DefaultHttpHeaders(cn.taketoday.http.DefaultHttpHeaders) LinkedCaseInsensitiveMap(cn.taketoday.util.LinkedCaseInsensitiveMap) DefaultHttpHeaders(cn.taketoday.http.DefaultHttpHeaders) MediaType(cn.taketoday.http.MediaType)

Example 4 with LinkedCaseInsensitiveMap

use of cn.taketoday.util.LinkedCaseInsensitiveMap in project today-framework by TAKETODAY.

the class UtilNamespaceHandlerTests method testMapWithTypes.

@Test
public void testMapWithTypes() {
    Map map = (Map) this.beanFactory.getBean("mapWithTypes");
    boolean condition = map instanceof LinkedCaseInsensitiveMap;
    assertThat(condition).isTrue();
    assertThat(map.get("bean")).isEqualTo(this.beanFactory.getBean("testBean"));
}
Also used : LinkedCaseInsensitiveMap(cn.taketoday.util.LinkedCaseInsensitiveMap) LinkedCaseInsensitiveMap(cn.taketoday.util.LinkedCaseInsensitiveMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

LinkedCaseInsensitiveMap (cn.taketoday.util.LinkedCaseInsensitiveMap)4 DefaultHttpHeaders (cn.taketoday.http.DefaultHttpHeaders)2 HttpHeaders (cn.taketoday.http.HttpHeaders)2 MediaType (cn.taketoday.http.MediaType)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 Test (org.junit.jupiter.api.Test)2