001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.autoconfigure.http;
018
019import java.nio.charset.Charset;
020import java.nio.charset.StandardCharsets;
021import java.util.Locale;
022import java.util.Map;
023
024import org.springframework.boot.context.properties.ConfigurationProperties;
025
026/**
027 * HTTP properties.
028 *
029 * @author Phillip Webb
030 * @author Stephane Nicoll
031 * @author Brian Clozel
032 * @since 2.1.0
033 */
034@ConfigurationProperties(prefix = "spring.http")
035public class HttpProperties {
036
037        /**
038         * Whether logging of (potentially sensitive) request details at DEBUG and TRACE level
039         * is allowed.
040         */
041        private boolean logRequestDetails;
042
043        /**
044         * HTTP encoding properties.
045         */
046        private final Encoding encoding = new Encoding();
047
048        public boolean isLogRequestDetails() {
049                return this.logRequestDetails;
050        }
051
052        public void setLogRequestDetails(boolean logRequestDetails) {
053                this.logRequestDetails = logRequestDetails;
054        }
055
056        public Encoding getEncoding() {
057                return this.encoding;
058        }
059
060        /**
061         * Configuration properties for http encoding.
062         */
063        public static class Encoding {
064
065                public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
066
067                /**
068                 * Charset of HTTP requests and responses. Added to the "Content-Type" header if
069                 * not set explicitly.
070                 */
071                private Charset charset = DEFAULT_CHARSET;
072
073                /**
074                 * Whether to force the encoding to the configured charset on HTTP requests and
075                 * responses.
076                 */
077                private Boolean force;
078
079                /**
080                 * Whether to force the encoding to the configured charset on HTTP requests.
081                 * Defaults to true when "force" has not been specified.
082                 */
083                private Boolean forceRequest;
084
085                /**
086                 * Whether to force the encoding to the configured charset on HTTP responses.
087                 */
088                private Boolean forceResponse;
089
090                /**
091                 * Locale in which to encode mapping.
092                 */
093                private Map<Locale, Charset> mapping;
094
095                public Charset getCharset() {
096                        return this.charset;
097                }
098
099                public void setCharset(Charset charset) {
100                        this.charset = charset;
101                }
102
103                public boolean isForce() {
104                        return Boolean.TRUE.equals(this.force);
105                }
106
107                public void setForce(boolean force) {
108                        this.force = force;
109                }
110
111                public boolean isForceRequest() {
112                        return Boolean.TRUE.equals(this.forceRequest);
113                }
114
115                public void setForceRequest(boolean forceRequest) {
116                        this.forceRequest = forceRequest;
117                }
118
119                public boolean isForceResponse() {
120                        return Boolean.TRUE.equals(this.forceResponse);
121                }
122
123                public void setForceResponse(boolean forceResponse) {
124                        this.forceResponse = forceResponse;
125                }
126
127                public Map<Locale, Charset> getMapping() {
128                        return this.mapping;
129                }
130
131                public void setMapping(Map<Locale, Charset> mapping) {
132                        this.mapping = mapping;
133                }
134
135                public boolean shouldForce(Type type) {
136                        Boolean force = (type != Type.REQUEST) ? this.forceResponse
137                                        : this.forceRequest;
138                        if (force == null) {
139                                force = this.force;
140                        }
141                        if (force == null) {
142                                force = (type == Type.REQUEST);
143                        }
144                        return force;
145                }
146
147                public enum Type {
148
149                        REQUEST, RESPONSE
150
151                }
152
153        }
154
155}