Merge branch '5.1.x'
This commit is contained in:
commit
a9f0eae4ab
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2018 the original author or authors.
|
* Copyright 2002-2019 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpInputMessage;
|
import org.springframework.http.HttpInputMessage;
|
||||||
import org.springframework.http.HttpOutputMessage;
|
import org.springframework.http.HttpOutputMessage;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
@ -72,7 +73,9 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether the {@code Accept-Charset} should be written to any outgoing request.
|
* Whether the {@code Accept-Charset} header should be written to any outgoing
|
||||||
|
* request sourced from the value of {@link Charset#availableCharsets()}.
|
||||||
|
* The behavior is suppressed if the header has already been set.
|
||||||
* <p>Default is {@code true}.
|
* <p>Default is {@code true}.
|
||||||
*/
|
*/
|
||||||
public void setWriteAcceptCharset(boolean writeAcceptCharset) {
|
public void setWriteAcceptCharset(boolean writeAcceptCharset) {
|
||||||
|
|
@ -99,10 +102,11 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter<Str
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeInternal(String str, HttpOutputMessage outputMessage) throws IOException {
|
protected void writeInternal(String str, HttpOutputMessage outputMessage) throws IOException {
|
||||||
if (this.writeAcceptCharset) {
|
HttpHeaders headers = outputMessage.getHeaders();
|
||||||
outputMessage.getHeaders().setAcceptCharset(getAcceptedCharsets());
|
if (this.writeAcceptCharset && headers.get(HttpHeaders.ACCEPT_CHARSET) == null) {
|
||||||
|
headers.setAcceptCharset(getAcceptedCharsets());
|
||||||
}
|
}
|
||||||
Charset charset = getContentTypeCharset(outputMessage.getHeaders().getContentType());
|
Charset charset = getContentTypeCharset(headers.getContentType());
|
||||||
StreamUtils.copy(str, charset, outputMessage.getBody());
|
StreamUtils.copy(str, charset, outputMessage.getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue