tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Content-Length header set automatically?
Date Fri, 10 Jan 2003 00:15:04 GMT


On Thu, 9 Jan 2003, Justin Ruthenbeck wrote:

> Date: Thu, 09 Jan 2003 15:09:44 -0800
> From: Justin Ruthenbeck <justinr@nextengine.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> Subject: Content-Length header set automatically?
>
>
> All appservers I've worked with have included the Content-Length header in
> all HTTP responses without any specific setting by a developer.  So far as
> I know, this is not a spec requirement, though it seems to be common
> practice.  Anyone out there know Tomcat's specific behavior on this?  Is
> the Content-Length header set on all requests by default?  Is it set only
> on certain requests?
>

In general, container setting of the content length is not required
because the length cannot always be known in advance.  HTTP headers are
sent before the response body, so if your response is longer than the
amount that is being buffered, there's no way for Tomcat to predict what
it will be.

> I ask because we're using persistent connections with HTTP 1.1 but have a
> custom client (non-browser) who requires and accurate Content-Length
> header.  My preference would be to have Tomcat handle the setting of the
> header, but I'm seeing XML HTTP responses without the header set.
>
> Any thoughts on the topic would be greatly appreciated...

[The following describes my understanding of how Coyote works for Tomcat
4.x and 5.x -- don't know about 3.3 or responding through a webserver
connector.]

Tomcat sets the content length automatically in two circumstances:

* Static files delivered by the default file-serving servlet
  (because the length is known ahead of time from the directory
  entry for that file)

* When the response data is small enough to fit into the
  response buffer, and has not been flushed yet, and no
  content length header was set by the application.

You can tweak the response buffer size (response.setBufferSize()) if you
want to increase the number of responses that fall into the second
category, but for anything longer than the response buffer size, it is
your responsibility to buffer the data you're generating so that you can
calculate and set the content length -- *before* writing any data to the
response.

>
> Thanks,
> justin

Craig


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message