Sync between MockHttpServletResponse copies

See gh-22466
This commit is contained in:
Juergen Hoeller 2019-02-25 23:14:37 +01:00
parent c31613dc74
commit 5c2f3079fd
2 changed files with 10 additions and 8 deletions

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -193,7 +193,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
Assert.state(this.writerAccessAllowed, "Writer access not allowed");
if (this.writer == null) {
Writer targetWriter = (this.characterEncoding != null ?
new OutputStreamWriter(this.content, this.characterEncoding) : new OutputStreamWriter(this.content));
new OutputStreamWriter(this.content, this.characterEncoding) :
new OutputStreamWriter(this.content));
this.writer = new ResponsePrintWriter(targetWriter);
}
return this.writer;

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -168,11 +168,11 @@ public class MockHttpServletResponse implements HttpServletResponse {
private void updateContentTypeHeader() {
if (this.contentType != null) {
StringBuilder sb = new StringBuilder(this.contentType);
if (!this.contentType.toLowerCase().contains(CHARSET_PREFIX) && this.charset) {
sb.append(";").append(CHARSET_PREFIX).append(this.characterEncoding);
String value = this.contentType;
if (this.charset && !this.contentType.toLowerCase().contains(CHARSET_PREFIX)) {
value = value + ';' + CHARSET_PREFIX + this.characterEncoding;
}
doAddHeaderValue(HttpHeaders.CONTENT_TYPE, sb.toString(), true);
doAddHeaderValue(HttpHeaders.CONTENT_TYPE, value, true);
}
}
@ -193,7 +193,8 @@ public class MockHttpServletResponse implements HttpServletResponse {
Assert.state(this.writerAccessAllowed, "Writer access not allowed");
if (this.writer == null) {
Writer targetWriter = (this.characterEncoding != null ?
new OutputStreamWriter(this.content, this.characterEncoding) : new OutputStreamWriter(this.content));
new OutputStreamWriter(this.content, this.characterEncoding) :
new OutputStreamWriter(this.content));
this.writer = new ResponsePrintWriter(targetWriter);
}
return this.writer;