Skip to content

Commit

Permalink
Do not set the response content-length in the NoDecorator, as it is i…
Browse files Browse the repository at this point in the history
…mpossible to know the content-length in bytes when we don't know the encoding (sitemesh 2.4 used to assume UTF-8, but setting the content-length is not a significant advantage anyway).

Therefore, remove all references to content-length as it is only used by NoDecorator.

(Fixes bug JRADEV-6607)
  • Loading branch information
spudbean committed Jul 13, 2011
1 parent 2ec48b2 commit 4fcde51
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
build
target
out
*.iml
*.ipr
*.iws
.idea
dist
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ compile.nowarn = off

Name = OpenSymphony SiteMesh
name = sitemesh
version = 2.5-atlassian-2
version = 2.5-atlassian-3
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<modelVersion>4.0.0</modelVersion>

<!--
ant clean test
ant clean jar sources
mvn deploy:deploy-file -Dfile=./dist/sitemesh-2.5-atlassian-2.jar -DpomFile=./pom.xml -Durl=https://maven.atlassian.com/public -DrepositoryId=atlassian-public
mvn deploy:deploy-file -Dfile=./dist/sitemesh-2.5-atlassian-2-sources.jar -DpomFile=./pom.xml -Dclassifier=sources -Durl=https://maven.atlassian.com/public -DrepositoryId=atlassian-public
-->

<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.5-atlassian-2</version>
<version>2.5-atlassian-3</version>

<packaging>jar</packaging>
<name>SiteMesh</name>
Expand Down
8 changes: 0 additions & 8 deletions src/java/com/opensymphony/module/sitemesh/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ public interface Page {
*/
String getTitle();

/**
* Length of the <code>Page</code>, in the format before
* it was parsed.
*
* @return Length of page data (in number of bytes).
*/
int getContentLength();

/**
* Get a property embedded into the <code>Page</code> as a <code>String</code>.
*
Expand Down
27 changes: 0 additions & 27 deletions src/java/com/opensymphony/module/sitemesh/parser/AbstractPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ public String getTitle() {
return noNull(getProperty("title"));
}

public int getContentLength() {
// We encode it but not into a new buffer
CountingOutputStream counter = new CountingOutputStream();
try
{
OutputStreamWriter writer = new OutputStreamWriter(counter);
writePage(writer);
// We must flush, because the writer will buffer
writer.flush();
} catch (IOException ioe) {
// Ignore, it's not possible with our OutputStream
}
return counter.getCount();
}

public String getProperty(String name) {
if (!isPropertySet(name)) return null;
return (String)properties.get(name);
Expand Down Expand Up @@ -180,18 +165,6 @@ protected static String noNull(String in) {
return in == null ? "" : in;
}

private static class CountingOutputStream extends OutputStream {
private int count = 0;

@Override
public void write(int i) throws IOException {
count++;
}

public int getCount() {
return count;
}
}
}

class PageRequest extends HttpServletRequestWrapper {
Expand Down
6 changes: 0 additions & 6 deletions src/java/com/opensymphony/sitemesh/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ public interface Content {
*/
void writeOriginal(Writer writer) throws IOException;

/**
* Length of the original unprocessed content.
*/
int originalLength();


/**
* Write the contents of the <code>&lt;body&gt;</code> tag.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ public String getTitle() {
return content.getTitle();
}

public int getContentLength() {
return content.originalLength();
}

public String getProperty(String name) {
return content.getProperty(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public void writeOriginal(Writer out) throws IOException {
page.writePage(out);
}

public int originalLength() {
return page.getContentLength();
}

public void writeBody(Writer out) throws IOException {
page.writeBody(out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ protected void render(Content content, HttpServletRequest request, HttpServletRe
ServletContext servletContext, SiteMeshWebAppContext webAppContext)
throws IOException, ServletException {

response.setContentLength(content.originalLength());

if (webAppContext.isUsingStream()) {
PrintWriter writer = new PrintWriter(response.getOutputStream());
content.writeOriginal(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public void testContentSanity() throws Exception {
Page bigPage = parser.parse(new DefaultSitemeshBuffer(bigChars, chars.length));

assertEquals(bigPage.getPage(), page.getPage());
assertEquals(bigPage.getContentLength(), page.getContentLength());
}

private String join(String[] values) {
Expand Down

0 comments on commit 4fcde51

Please sign in to comment.