On Tue, 29 Oct 2002, Alex Muc wrote:

> Date: Tue, 29 Oct 2002 22:39:54 -0500
> From: Alex Muc <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Removing Response Headers
>
> Hi,
>
> I'm trying to find a way to remove response headers from the default set
> of response headers that Tomcat sends back to the browser with each
> request.  From my analysis here's what Tomcat sends back by default on
> most requests:
>
> HTTP/1.1 200 OK
> Content-Type: text/html;ISO-8859-1
> Date: Wed, 30 Oct 2002 03:09:21 GMT
> Server: Apache Tomcat/4.0.4 (HTTP/1.1 Connector)
> Transfer-Encoding: chunked
> Set-Cookie: JSESSIONID=E0A77CD43161227E989CE9C0BA3C6D8F;Path=/cc
>
> [body of the request here]
>
> I'd like to be able to get rid of the Date, Server and Set-Cookie
> header.  I don't see anyway to do this using the methods provided on
> HttpServletResponse.  That object only has methods for adding header
> fields.  I briefly investigated using a filter to do this, but I don't a
> filter will give me access to the header part of the response, only the
> main body of the HTTP response.  I may be wrong about this, so please
> correct me if you know otherwise.
>
> Why do I want to do this?  I'm writing an application for the J2ME MIDP
> specification which is to run on Palm Pilot devices.  I'm doing
> performance testing and the Palm Pilot is spending a significant amount
> of time processing the response headers that are coming into it as
> responses from web pages that it is requesting from my Tomcat server.
> My testing indicates that it takes the Palm Pilot approximately 1/2 of a
> second to process each additional response header.  This adds up to a
> lot of extra air time and unnecessary processing time.  I need to
> minimize the amount of data that is transmitted between the Palm Pilot
> and the server so that it runs as fast as possible.  The way I arrived
> at the 1/2 of a second per response header figure was by adding extra
> headers to the request and timing how much longer than normal the
> processing took.
>
> I'm hoping someone can tell me if this is possible or not.
>

There's two different answers, depending on whether the headers are added
by a servlet or by the container itself.

* For headers added by a servlet (the "Date" header is added by
  the default file-serving servlet), you can use a Filter, but
  you have to create a wrapper around the response (extend
  HttpServletResponseWrapper).  In your custom wrapper class,
  you would explicitly ignore the headers that you don't want to
  actually send, by overriding methods like setHeader().

* For headers added by the container (the "Server" and "Set-Cookie"
  headers in your case), a Filter won't do the trick, because they
  are typically implemented inside the container's implementation
  class for the response.  For that, you'd need to create a Valve
  (Tomcat specific) that accomplished essentially the same purpose
  inside the container as a Filter does inside a webapp -- it would
  create a wrapper around Tomcat's internal HttpResponse class, and
  override the methods where those headers are created.

For the Set-Cookie header for JSESSIONID in particular, you can also
employ one of the following (much easier) techniques:

* Ensure that your webapp does not use sessions (so the session id
  cookie would never get set)

* Set the "cookies" attribute of the <Context> element for your webapp
  to false, so that cookies will not be used for session maintenance
  (you will need to perform URL rewriting if you still need sessions
  in this scenario).

> Thank you for your assistance.
>
> Alex.

Craig


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

Reply via email to