Bug 50748 - Ignoring setContentLength( ) when using writer is incomplete
Ignoring setContentLength( ) when using writer is incomplete
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
trunk
PC Windows XP
: P2 minor (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
: 50747 (view as bug list)
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2011-02-09 16:48 UTC by Konstantin Kolinko
Modified: 2011-02-09 17:40 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kolinko 2011-02-09 16:48:03 UTC
Reviewing o.a.c.connector.Response after comments in
https://issues.apache.org/bugzilla/show_bug.cgi?id=50747#c3

In o.a.c.connector.Response there is a feature that Response#setContentLength(int) ignores the call if usingWriter flag is true.


My comments are:

1) It concerns only multi-byte charsets such as UTF-8. There is nothing wrong with calling setContentLength() if it is a single-byte charset.

2) There is no such protection in Response#setHeader(), #setIntHeader(), #addHeader(), #addIntHeader() methods. Calling them will bypass the protection.

See how o.a.coyote.Response implements those methods and o.a.coyote.Response#checkSpecialHeader() for comparison.
Comment 1 Mark Thomas 2011-02-09 17:19:52 UTC
*** Bug 50747 has been marked as a duplicate of this bug. ***
Comment 2 Mark Thomas 2011-02-09 17:40:44 UTC
This fixed in 7.0.x and will be included in 7.0.9 onwards.

Both single and multi-byte encodings are handled since OutputBuffer.close() sets the content-length to the number of bytes, not the number of characters.

I suspect the test in the response dates from a time when content length was set using characters although I haven't done the code archeology to be sure of that.