Skip to content

Commit 5c8c8a0

Browse files
committed
LDEV-5952 correct internalRequest behavior with resetBuffer
https://luceeserver.atlassian.net/browse/LDEV-5952
1 parent 196f7f1 commit 5c8c8a0

File tree

8 files changed

+131
-2
lines changed

8 files changed

+131
-2
lines changed

core/src/main/java/lucee/runtime/net/http/HttpServletResponseDummy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public void flushBuffer() throws IOException {
198198

199199
@Override
200200
public void resetBuffer() {
201-
commited = true;
201+
if (commited) throw new IllegalStateException("Cannot reset buffer after response has been committed");
202202
}
203203

204204
@Override
@@ -208,7 +208,7 @@ public boolean isCommitted() {
208208

209209
@Override
210210
public void reset() {
211-
commited = true;
211+
if (commited) throw new IllegalStateException("Cannot reset buffer after response has been committed");
212212
}
213213

214214
@Override

test/tickets/LDEV5952.cfc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
component extends="org.lucee.cfml.test.LuceeTestCase" labels="internalRequest,cfcontent" {
2+
3+
function run( testResults, testBox ) {
4+
describe( "LDEV-5952 - _internalRequest fails with 'Content was already flushed' after resetBuffer()", function() {
5+
6+
it( "cfcontent should work after resetBuffer() is called", function() {
7+
var result = _internalRequest(
8+
template = createURI( "LDEV5952/resetBuffer.cfm" ),
9+
method = "GET",
10+
throwonerror = false
11+
);
12+
13+
expect( result ).toHaveKey( "filecontent" );
14+
expect( result ).notToHaveKey( "error" );
15+
expect( result.status_code ).toBe( 200 );
16+
expect( result.headers[ "content-type" ] ).toInclude( "application/json" );
17+
18+
var content = deserializeJSON( result.filecontent );
19+
expect( content.success ).toBeTrue();
20+
});
21+
22+
it( "cfcontent should work after reset() is called", function() {
23+
var result = _internalRequest(
24+
template = createURI( "LDEV5952/reset.cfm" ),
25+
method = "GET",
26+
throwonerror = false
27+
);
28+
29+
expect( result ).toHaveKey( "filecontent" );
30+
expect( result ).notToHaveKey( "error" );
31+
expect( result.status_code ).toBe( 200 );
32+
expect( result.headers[ "content-type" ] ).toInclude( "application/json" );
33+
34+
var content = deserializeJSON( result.filecontent );
35+
expect( content.success ).toBeTrue();
36+
});
37+
38+
it( "cfcontent should work without any buffer manipulation", function() {
39+
var result = _internalRequest(
40+
template = createURI( "LDEV5952/simple.cfm" ),
41+
method = "GET",
42+
throwonerror = false
43+
);
44+
45+
expect( result ).toHaveKey( "filecontent" );
46+
expect( result ).notToHaveKey( "error" );
47+
expect( result.status_code ).toBe( 200 );
48+
expect( result.headers[ "content-type" ] ).toInclude( "application/json" );
49+
50+
var content = deserializeJSON( result.filecontent );
51+
expect( content.success ).toBeTrue();
52+
});
53+
54+
it( "resetBuffer() should fail after flushBuffer()", function() {
55+
var result = _internalRequest(
56+
template = createURI( "LDEV5952/resetBufferAfterFlush.cfm" ),
57+
method = "GET",
58+
throwonerror = false
59+
);
60+
61+
expect( result ).toHaveKey( "error" );
62+
expect( result.error.message ).toInclude( "committed" );
63+
});
64+
65+
it( "reset() should fail after flushBuffer()", function() {
66+
var result = _internalRequest(
67+
template = createURI( "LDEV5952/resetAfterFlush.cfm" ),
68+
method = "GET",
69+
throwonerror = false
70+
);
71+
72+
expect( result ).toHaveKey( "error" );
73+
expect( result.error.message ).toInclude( "committed" );
74+
});
75+
76+
});
77+
}
78+
79+
private string function createURI( string calledName ) {
80+
var baseURI = "/test/#listLast( getDirectoryFromPath( getCurrenttemplatepath() ), "\/" )#/";
81+
return baseURI & calledName;
82+
}
83+
84+
}

test/tickets/LDEV5952/reset.cfm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<cfscript>
2+
response = getPageContext().getResponse();
3+
response.reset();
4+
cfcontent( type="application/json" );
5+
writeOutput( serializeJSON( { "success": true, "test": "reset" } ) );
6+
</cfscript>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<cfscript>
2+
response = getPageContext().getResponse();
3+
writeOutput( "some content" );
4+
response.flushBuffer();
5+
response.reset();
6+
cfcontent( type="application/json" );
7+
writeOutput( serializeJSON( { "success": true, "test": "resetAfterFlush" } ) );
8+
</cfscript>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<cfscript>
2+
response = getPageContext().getResponse();
3+
response.resetBuffer();
4+
cfcontent( type="application/json" );
5+
writeOutput( serializeJSON( { "success": true, "test": "resetBuffer" } ) );
6+
</cfscript>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<cfscript>
2+
response = getPageContext().getResponse();
3+
writeOutput( "some content" );
4+
response.flushBuffer();
5+
response.resetBuffer();
6+
cfcontent( type="application/json" );
7+
writeOutput( serializeJSON( { "success": true, "test": "resetBufferAfterFlush" } ) );
8+
</cfscript>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<cfscript>
2+
try {
3+
response = getPageContext().getResponse();
4+
writeOutput( "some content" );
5+
response.flushBuffer();
6+
response.resetBuffer();
7+
cfcontent( type="application/json" );
8+
writeOutput( serializeJSON( { "success": true, "test": "resetBufferAfterFlush" } ) );
9+
}
10+
catch ( any e ) {
11+
writeOutput( "ERROR: " & e.message & " | " & e.detail );
12+
}
13+
</cfscript>

test/tickets/LDEV5952/simple.cfm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<cfscript>
2+
cfcontent( type="application/json" );
3+
writeOutput( serializeJSON( { "success": true, "test": "simple" } ) );
4+
</cfscript>

0 commit comments

Comments
 (0)