File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
main/java/org/apache/sling/engine/impl
test/java/org/apache/sling/engine/impl Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -325,7 +325,7 @@ private String getCurrentStackTrace() {
325
325
326
326
@ Override
327
327
public void setContentType (final String type ) {
328
- if (!isInclude ()) {
328
+ if (super . getResponse (). isCommitted () || !isInclude ()) {
329
329
super .setContentType (type );
330
330
} else {
331
331
Optional <String > message = checkContentTypeOverride (type );
@@ -358,7 +358,7 @@ public void setContentType(final String type) {
358
358
* @param contentType the 'Content-Type' value that is being set
359
359
* @return an optional message to log
360
360
*/
361
- private Optional <String > checkContentTypeOverride (@ Nullable String contentType ) {
361
+ protected Optional <String > checkContentTypeOverride (@ Nullable String contentType ) {
362
362
if (requestData .getSlingRequestProcessor ().getContentTypeHeaderState () == ContentTypeHeaderState .VIOLATED ) {
363
363
// return immediatly as the content type header has already been violated
364
364
// prevoiously, no more checks needed
Original file line number Diff line number Diff line change @@ -87,6 +87,24 @@ public class SlingHttpServletResponseImplTest {
87
87
"4749 LOG Adding bindings took 4 microseconds"
88
88
};
89
89
90
+ @ Test
91
+ public void testNoViolationChecksOnCommitedResponse () {
92
+ final SlingHttpServletResponse orig = Mockito .mock (SlingHttpServletResponse .class );
93
+ Mockito .when (orig .isCommitted ()).thenReturn (true );
94
+
95
+ final RequestData requestData = mock (RequestData .class );
96
+ final DispatchingInfo info = new DispatchingInfo (DispatcherType .INCLUDE );
97
+ when (requestData .getDispatchingInfo ()).thenReturn (info );
98
+ info .setProtectHeadersOnInclude (true );
99
+
100
+ final SlingHttpServletResponseImpl include = new SlingHttpServletResponseImpl (requestData , orig );
101
+ SlingHttpServletResponseImpl spyInclude = Mockito .spy (include );
102
+
103
+ spyInclude .setContentType ("someOtherType" );
104
+ Mockito .verify (orig , times (1 )).setContentType (Mockito .any ());
105
+ Mockito .verify (spyInclude , never ()).checkContentTypeOverride (Mockito .any ());
106
+ }
107
+
90
108
@ Test
91
109
public void testReset () {
92
110
final SlingHttpServletResponse orig = mock (SlingHttpServletResponse .class );
You can’t perform that action at this time.
0 commit comments