File tree 5 files changed +35
-15
lines changed
autoconfigure-adapter/src/main/java/org/springframework/boot/autoconfigure/web/reactive
jafu/src/main/java/org/springframework/fu/jafu/web
kofu/src/main/kotlin/org/springframework/fu/kofu/web 5 files changed +35
-15
lines changed Original file line number Diff line number Diff line change 27
27
*/
28
28
public class StringCodecInitializer extends AbstractCodecInitializer {
29
29
30
- public StringCodecInitializer (boolean isClientCodec ) {
30
+ private final boolean textPlainOnly ;
31
+
32
+ public StringCodecInitializer (boolean isClientCodec , boolean textPlainOnly ) {
31
33
super (isClientCodec );
34
+ this .textPlainOnly = textPlainOnly ;
32
35
}
33
36
34
37
@ Override
35
38
protected void register (GenericApplicationContext context , CodecConfigurer configurer ) {
36
- configurer .customCodecs ().encoder (CharSequenceEncoder .textPlainOnly ());
37
- configurer .customCodecs ().decoder (StringDecoder .textPlainOnly ());
39
+ configurer .customCodecs ().encoder (textPlainOnly ? CharSequenceEncoder .textPlainOnly () : CharSequenceEncoder . allMimeTypes ());
40
+ configurer .customCodecs ().decoder (textPlainOnly ? StringDecoder .textPlainOnly () : StringDecoder . allMimeTypes ());
38
41
}
39
42
}
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ public void initialize(GenericApplicationContext context) {
79
79
super .initialize (context );
80
80
this .dsl .accept (this );
81
81
if (!this .codecsConfigured ) {
82
- new StringCodecInitializer (true ).initialize (context );
82
+ new StringCodecInitializer (true , false ).initialize (context );
83
83
new ResourceCodecInitializer (true ).initialize (context );
84
84
}
85
85
new ReactiveWebClientBuilderInitializer (baseUrl ).initialize (context );
@@ -108,10 +108,19 @@ public void initialize(GenericApplicationContext context) {
108
108
}
109
109
110
110
/**
111
- * Enable {@link org.springframework.core.codec.CharSequenceEncoder} and {@link org.springframework.core.codec.StringDecoder}
111
+ * Enable {@link org.springframework.core.codec.CharSequenceEncoder} and {@link org.springframework.core.codec.StringDecoder} for all media types
112
+ * @see #string(boolean)
112
113
*/
113
114
public WebFluxClientCodecDsl string () {
114
- new StringCodecInitializer (true ).initialize (context );
115
+ new StringCodecInitializer (true , false ).initialize (context );
116
+ return this ;
117
+ }
118
+
119
+ /**
120
+ * Enable {@link org.springframework.core.codec.CharSequenceEncoder} and {@link org.springframework.core.codec.StringDecoder}
121
+ */
122
+ public WebFluxClientCodecDsl string (boolean textPlainOnly ) {
123
+ new StringCodecInitializer (true , textPlainOnly ).initialize (context );
115
124
return this ;
116
125
}
117
126
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ public void initialize(GenericApplicationContext context) {
154
154
engine .setPort (port );
155
155
156
156
if (!codecsConfigured ) {
157
- new StringCodecInitializer (false ).initialize (context );
157
+ new StringCodecInitializer (false , false ).initialize (context );
158
158
new ResourceCodecInitializer (false ).initialize (context );
159
159
}
160
160
if (context .containsBeanDefinition ("webHandler" )) {
@@ -187,10 +187,18 @@ public void initialize(GenericApplicationContext context) {
187
187
}
188
188
189
189
/**
190
- * Enable {@link org.springframework.core.codec.CharSequenceEncoder} and {@link org.springframework.core.codec.StringDecoder}
190
+ * Enable {@link org.springframework.core.codec.CharSequenceEncoder} and {@link org.springframework.core.codec.StringDecoder} for all media types
191
191
*/
192
192
public WebFluxServerCodecDsl string () {
193
- new StringCodecInitializer (false ).initialize (context );
193
+ new StringCodecInitializer (false , false ).initialize (context );
194
+ return this ;
195
+ }
196
+
197
+ /**
198
+ * Enable {@link org.springframework.core.codec.CharSequenceEncoder} and {@link org.springframework.core.codec.StringDecoder}
199
+ */
200
+ public WebFluxServerCodecDsl string (boolean textPlainOnly ) {
201
+ new StringCodecInitializer (false , textPlainOnly ).initialize (context );
194
202
return this ;
195
203
}
196
204
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class WebFluxClientDsl(private val init: WebFluxClientDsl.() -> Unit) : Abstract
35
35
super .initialize(context)
36
36
init ()
37
37
if (! codecsConfigured) {
38
- StringCodecInitializer (true ).initialize(context)
38
+ StringCodecInitializer (true , false ).initialize(context)
39
39
ResourceCodecInitializer (true ).initialize(context)
40
40
}
41
41
ReactiveWebClientBuilderInitializer (baseUrl).initialize(context)
@@ -59,8 +59,8 @@ class WebFluxClientDsl(private val init: WebFluxClientDsl.() -> Unit) : Abstract
59
59
/* *
60
60
* Enable [org.springframework.core.codec.CharSequenceEncoder] and [org.springframework.core.codec.StringDecoder]
61
61
*/
62
- fun string () {
63
- StringCodecInitializer (true ).initialize(context)
62
+ fun string (textPlainOnly : Boolean = false ) {
63
+ StringCodecInitializer (true , textPlainOnly ).initialize(context)
64
64
}
65
65
66
66
/* *
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ open class WebFluxServerDsl(private val init: WebFluxServerDsl.() -> Unit): Abst
73
73
}
74
74
engine!! .setPort(port)
75
75
if (! codecsConfigured) {
76
- StringCodecInitializer (false ).initialize(context)
76
+ StringCodecInitializer (false , false ).initialize(context)
77
77
ResourceCodecInitializer (false ).initialize(context)
78
78
}
79
79
if (context.containsBeanDefinition(" webHandler" )) {
@@ -218,8 +218,8 @@ open class WebFluxServerDsl(private val init: WebFluxServerDsl.() -> Unit): Abst
218
218
/* *
219
219
* Enable [org.springframework.core.codec.CharSequenceEncoder] and [org.springframework.core.codec.StringDecoder]
220
220
*/
221
- fun string () {
222
- StringCodecInitializer (false ).initialize(context)
221
+ fun string (textPlainOnly : Boolean = false ) {
222
+ StringCodecInitializer (false , textPlainOnly ).initialize(context)
223
223
}
224
224
225
225
/* *
You can’t perform that action at this time.
0 commit comments