Skip to content

Commit ba56004

Browse files
committed
Revert "Keep the Last-Modified header for large unbuffered SSI
documents" Set last-modifed as best effort. This reverts commit 363ec9f.
1 parent 9bf0631 commit ba56004

2 files changed

Lines changed: 3 additions & 51 deletions

File tree

‎java/org/apache/catalina/ssi/SSIServlet.java‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,9 @@ protected void processSSI(HttpServletRequest req, HttpServletResponse res, URL r
211211
}
212212

213213
try (BufferedReader bufferedReader = new BufferedReader(isr)) {
214-
// Set the header from the source before the output is generated. In the
215-
// unbuffered mode a response larger than the response buffer is committed
216-
// while processing, after which setting the header is silently ignored.
217-
long sourceLastModified = resourceInfo.getLastModified();
218-
if (sourceLastModified > 0) {
219-
res.setDateHeader("last-modified", sourceLastModified);
220-
}
221-
long lastModified = ssiProcessor.process(bufferedReader, sourceLastModified, printWriter);
222-
if (lastModified > sourceLastModified && !res.isCommitted()) {
214+
long lastModified = ssiProcessor.process(bufferedReader, resourceInfo.getLastModified(), printWriter);
215+
// Setting last-modified as best effort
216+
if (lastModified > 0) {
223217
res.setDateHeader("last-modified", lastModified);
224218
}
225219
if (stringWriter != null) {

‎test/org/apache/catalina/ssi/TestSsiServlet.java‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -77,48 +77,6 @@ public void testServlet() throws Exception {
7777
}
7878

7979

80-
@Test
81-
public void testLargeDocumentLastModifiedHeader() throws Exception {
82-
// A document larger than the response buffer commits the unbuffered
83-
// response while the output is being generated. The Last-Modified
84-
// header must be set before that happens.
85-
Tomcat tomcat = getTomcatInstance();
86-
87-
File appDir = new File(getTemporaryDirectory(), "ssi-large");
88-
Assert.assertTrue(appDir.mkdirs() || appDir.isDirectory());
89-
addDeleteOnTearDown(appDir);
90-
File doc = new File(appDir, "large.shtml");
91-
try (Writer writer = new OutputStreamWriter(new FileOutputStream(doc), StandardCharsets.ISO_8859_1)) {
92-
writer.write("X".repeat(20000));
93-
writer.write("<!--#flastmod file=\"large.shtml\" -->TAIL");
94-
}
95-
96-
Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
97-
Tomcat.addServlet(ctxt, "ssi", new SSIServlet());
98-
ctxt.addServletMapping("*.shtml", "ssi");
99-
100-
tomcat.start();
101-
102-
Map<String,List<String>> resHeaders = new HashMap<>();
103-
String path = "http://localhost:" + getPort() + "/large.shtml";
104-
ByteChunk out = new ByteChunk();
105-
106-
int rc = getUrl(path, out, resHeaders);
107-
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
108-
String body = new String(out.getBuffer(), 0, out.getLength(), StandardCharsets.ISO_8859_1);
109-
Assert.assertTrue(body.endsWith("TAIL"));
110-
// Headers are case-insensitive. SSIServlet uses the lower-case name.
111-
String lastModified = null;
112-
for (Map.Entry<String,List<String>> header : resHeaders.entrySet()) {
113-
if ("Last-Modified".equalsIgnoreCase(header.getKey())) {
114-
Assert.assertEquals(1, header.getValue().size());
115-
lastModified = header.getValue().get(0);
116-
}
117-
}
118-
Assert.assertNotNull(lastModified);
119-
}
120-
121-
12280
@Test
12381
public void testBadConditionalExpressionReportsError() throws Exception {
12482
// A conditional directive with an expression that cannot be parsed

0 commit comments

Comments
 (0)