You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erik Hatcher <er...@ehatchersolutions.com> on 2004/03/30 22:19:27 UTC

Controlling HTTP Headers

How are folks controlling the caching headers (or any other headers for 
that matter) in the HTTP response from Tapestry applications?

I would like to ensure all the caching switches that browsers recognize 
(including the <meta> pragma one) are set to not cache at all, and in 
my delving into the Tapestry code and its ResponseOutputStream I don't 
see a way to add these headers.  Am I missing something?

I can get the <meta> one with no problem using the @Shell delegate, 
though.

Should I just use a servlet filter to set these headers?  Or should 
Tapestry itself allow a way to do this?

Thanks,
	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Controlling HTTP Headers

Posted by Paul Ferraro <pm...@columbia.edu>.
IMHO, using a filter seems more appropriate since it keeps business 
logic and server-related configuration separate.  In my experience with 
Tapestry, whenever I come across a ResponseOutputStream there is also a 
RequestContext available (almost always via the IRequestCycle) - so, if 
I need to, I access the ServletResponse via the RequestContext object.

Paul Ferraro

Erik Hatcher wrote:

> How are folks controlling the caching headers (or any other headers 
> for that matter) in the HTTP response from Tapestry applications?
>
> I would like to ensure all the caching switches that browsers 
> recognize (including the <meta> pragma one) are set to not cache at 
> all, and in my delving into the Tapestry code and its 
> ResponseOutputStream I don't see a way to add these headers.  Am I 
> missing something?
>
> I can get the <meta> one with no problem using the @Shell delegate, 
> though.
>
> Should I just use a servlet filter to set these headers?  Or should 
> Tapestry itself allow a way to do this?
>
> Thanks,
>     Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Controlling HTTP Headers

Posted by Jeff Markham <je...@markhamsoft.com>.
I'm using a standard servlet filter to accomplish this task.

Erik Hatcher wrote:

> How are folks controlling the caching headers (or any other headers for 
> that matter) in the HTTP response from Tapestry applications?
> 
> I would like to ensure all the caching switches that browsers recognize 
> (including the <meta> pragma one) are set to not cache at all, and in my 
> delving into the Tapestry code and its ResponseOutputStream I don't see 
> a way to add these headers.  Am I missing something?
> 
> I can get the <meta> one with no problem using the @Shell delegate, though.
> 
> Should I just use a servlet filter to set these headers?  Or should 
> Tapestry itself allow a way to do this?
> 
> Thanks,
>     Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Controlling HTTP Headers

Posted by Leif Stainsby <ls...@galdosinc.com>.
Hi Jonny,

I happened to have a handy reference [1] on HTTP. You are right in that meta
tags were introduced as a convenient way to introduce HTTP header
information into HTML files.  The problem is that not all servers or
browsers (or proxies for that matter) are guaranteed to handle meta tags in
the same manner.  This may result in unexpected caching behaviour.

A more robust approach is to set the HTTP headers directly as Erik wants to
do.

...Leif

[1] "HTTP (The Definitive Guide)",
    David Gourley and Brian Totty, O'Reilly, 2002
    ISBN:  1-56592-509-2

> -----Original Message-----
> From: Jonny Wray [mailto:jonny_wray@yahoo.com]
> Sent: Tuesday, March 30, 2004 5:31 PM
> To: Tapestry users
> Subject: Re: Controlling HTTP Headers
>
>
>
> Erik,
>
> no problem, glad it helped.
>
> However, maybe it's my misunderstanding of of html meta tags, but I
> thought a tag like,
>
> <meta http-equiv="name" content="value />
>
> actually had the same effect as putting the (name, value) pair into the
> HttpResponse header. ie my code below does do what you want it to,
> without directly accessing the RequestCycle.
>
> If not, then my code isn't doing what I want it to.
>
> Jonny
>
>
> --- Erik Hatcher <er...@ehatchersolutions.com> wrote:
> > Jonny - thanks for that!  Your code will save me a bit of time.  And
> > while you aren't setting the actual HTTP headers, just meta tags, it
> > now occurs to me that you could set the headers in the delegate after
> >
> > all since there is access to IRequestCycle.  Sweet.
> >
> > 	Erik
> >
> >
> > On Mar 30, 2004, at 3:34 PM, Jonny Wray wrote:
> >
> > >
> > > I used tapestry directly. Set the delegate attribute of the Shell
> > > component to my specific implementation of IRender. Here's my
> > class:
> > >
> > > public class HeaderDelegate implements IRender{
> > >
> > >   private class Attribute{
> > >     private String name;
> > >     private String value;
> > >
> > >     public Attribute(String name, String value){
> > >       this.name = name;
> > >       this.value = value;
> > >     }
> > >
> > >     public String getName(){
> > >        return name;
> > >     }
> > >
> > >     public String getValue(){
> > > 	return value;
> > >     }
> > >   }
> > >
> > >   public void render(IMarkupWriter writer, IRequestCycle cycle){
> > > 	List attributeList = new ArrayList();
> > > 	Attribute att = new Attribute("http-equiv", "Expires");
> > > 	attributeList.add(att);
> > > 	att = new Attribute("Content", "0");
> > > 	attributeList.add(att);
> > > 	createMetaTag(writer, attributeList);
> > >
> > > 	attributeList.clear();
> > > 	att = new Attribute("http-equiv", "Cache-Control");
> > > 	attributeList.add(att);
> > > 	att = new Attribute("Content", "must-revalidate, post-check=0,
> > > pre-check=0");
> > > 	attributeList.add(att);
> > > 	createMetaTag(writer, attributeList);
> > >
> > > 	attributeList.clear();
> > > 	att = new Attribute("http-equiv", "Pragma");
> > > 	attributeList.add(att);
> > > 	att = new Attribute("Content", "public");
> > > 	attributeList.add(att);
> > > 	createMetaTag(writer, attributeList);
> > >   }
> > >
> > >   private void createMetaTag(IMarkupWriter writer, List
> > attributes){
> > > 	writer.begin("meta");
> > > 	for(int i=0;i<attributes.size();i++){
> > > 		Attribute att = (Attribute)attributes.get(i);
> > > 		writer.attribute(att.getName(), att.getValue());
> > > 	}
> > > 	writer.closeTag();
> > >   }
> > > }
> > >
> > >
> > > --- Erik Hatcher <er...@ehatchersolutions.com> wrote:
> > >> How are folks controlling the caching headers (or any other
> > headers
> > >> for
> > >> that matter) in the HTTP response from Tapestry applications?
> > >>
> > >> I would like to ensure all the caching switches that browsers
> > >> recognize
> > >> (including the <meta> pragma one) are set to not cache at all, and
> > in
> > >>
> > >> my delving into the Tapestry code and its ResponseOutputStream I
> > >> don't
> > >> see a way to add these headers.  Am I missing something?
> > >>
> > >> I can get the <meta> one with no problem using the @Shell
> > delegate,
> > >> though.
> > >>
> > >> Should I just use a servlet filter to set these headers?  Or
> > should
> > >> Tapestry itself allow a way to do this?
> > >>
> > >> Thanks,
> > >> 	Erik
> > >>
> > >>
> > >>
> > ---------------------------------------------------------------------
> > >> To unsubscribe, e-mail:
> > tapestry-user-unsubscribe@jakarta.apache.org
> > >> For additional commands, e-mail:
> > >> tapestry-user-help@jakarta.apache.org
> > >>
> > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > tapestry-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Controlling HTTP Headers

Posted by Jonny Wray <jo...@yahoo.com>.
Erik,

no problem, glad it helped. 

However, maybe it's my misunderstanding of of html meta tags, but I
thought a tag like,

<meta http-equiv="name" content="value />

actually had the same effect as putting the (name, value) pair into the
HttpResponse header. ie my code below does do what you want it to,
without directly accessing the RequestCycle.

If not, then my code isn't doing what I want it to.

Jonny


--- Erik Hatcher <er...@ehatchersolutions.com> wrote:
> Jonny - thanks for that!  Your code will save me a bit of time.  And 
> while you aren't setting the actual HTTP headers, just meta tags, it 
> now occurs to me that you could set the headers in the delegate after
> 
> all since there is access to IRequestCycle.  Sweet.
> 
> 	Erik
> 
> 
> On Mar 30, 2004, at 3:34 PM, Jonny Wray wrote:
> 
> >
> > I used tapestry directly. Set the delegate attribute of the Shell
> > component to my specific implementation of IRender. Here's my
> class:
> >
> > public class HeaderDelegate implements IRender{
> > 	
> >   private class Attribute{
> >     private String name;
> >     private String value;
> > 		
> >     public Attribute(String name, String value){
> >       this.name = name;
> >       this.value = value;	
> >     }
> > 		
> >     public String getName(){
> >        return name;
> >     }
> > 		
> >     public String getValue(){
> > 	return value;
> >     }
> >   }
> > 	
> >   public void render(IMarkupWriter writer, IRequestCycle cycle){
> > 	List attributeList = new ArrayList();
> > 	Attribute att = new Attribute("http-equiv", "Expires");
> > 	attributeList.add(att);
> > 	att = new Attribute("Content", "0");
> > 	attributeList.add(att);
> > 	createMetaTag(writer, attributeList);
> > 		
> > 	attributeList.clear();
> > 	att = new Attribute("http-equiv", "Cache-Control");
> > 	attributeList.add(att);
> > 	att = new Attribute("Content", "must-revalidate, post-check=0,
> > pre-check=0");
> > 	attributeList.add(att);
> > 	createMetaTag(writer, attributeList);
> > 		
> > 	attributeList.clear();
> > 	att = new Attribute("http-equiv", "Pragma");
> > 	attributeList.add(att);
> > 	att = new Attribute("Content", "public");
> > 	attributeList.add(att);
> > 	createMetaTag(writer, attributeList);
> >   }
> > 	
> >   private void createMetaTag(IMarkupWriter writer, List
> attributes){
> > 	writer.begin("meta");
> > 	for(int i=0;i<attributes.size();i++){
> > 		Attribute att = (Attribute)attributes.get(i);
> > 		writer.attribute(att.getName(), att.getValue());
> > 	}
> > 	writer.closeTag();
> >   }
> > }
> >
> >
> > --- Erik Hatcher <er...@ehatchersolutions.com> wrote:
> >> How are folks controlling the caching headers (or any other
> headers
> >> for
> >> that matter) in the HTTP response from Tapestry applications?
> >>
> >> I would like to ensure all the caching switches that browsers
> >> recognize
> >> (including the <meta> pragma one) are set to not cache at all, and
> in
> >>
> >> my delving into the Tapestry code and its ResponseOutputStream I
> >> don't
> >> see a way to add these headers.  Am I missing something?
> >>
> >> I can get the <meta> one with no problem using the @Shell
> delegate,
> >> though.
> >>
> >> Should I just use a servlet filter to set these headers?  Or
> should
> >> Tapestry itself allow a way to do this?
> >>
> >> Thanks,
> >> 	Erik
> >>
> >>
> >>
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail:
> >> tapestry-user-help@jakarta.apache.org
> >>
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Controlling HTTP Headers

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Jonny - thanks for that!  Your code will save me a bit of time.  And 
while you aren't setting the actual HTTP headers, just meta tags, it 
now occurs to me that you could set the headers in the delegate after 
all since there is access to IRequestCycle.  Sweet.

	Erik


On Mar 30, 2004, at 3:34 PM, Jonny Wray wrote:

>
> I used tapestry directly. Set the delegate attribute of the Shell
> component to my specific implementation of IRender. Here's my class:
>
> public class HeaderDelegate implements IRender{
> 	
>   private class Attribute{
>     private String name;
>     private String value;
> 		
>     public Attribute(String name, String value){
>       this.name = name;
>       this.value = value;	
>     }
> 		
>     public String getName(){
>        return name;
>     }
> 		
>     public String getValue(){
> 	return value;
>     }
>   }
> 	
>   public void render(IMarkupWriter writer, IRequestCycle cycle){
> 	List attributeList = new ArrayList();
> 	Attribute att = new Attribute("http-equiv", "Expires");
> 	attributeList.add(att);
> 	att = new Attribute("Content", "0");
> 	attributeList.add(att);
> 	createMetaTag(writer, attributeList);
> 		
> 	attributeList.clear();
> 	att = new Attribute("http-equiv", "Cache-Control");
> 	attributeList.add(att);
> 	att = new Attribute("Content", "must-revalidate, post-check=0,
> pre-check=0");
> 	attributeList.add(att);
> 	createMetaTag(writer, attributeList);
> 		
> 	attributeList.clear();
> 	att = new Attribute("http-equiv", "Pragma");
> 	attributeList.add(att);
> 	att = new Attribute("Content", "public");
> 	attributeList.add(att);
> 	createMetaTag(writer, attributeList);
>   }
> 	
>   private void createMetaTag(IMarkupWriter writer, List attributes){
> 	writer.begin("meta");
> 	for(int i=0;i<attributes.size();i++){
> 		Attribute att = (Attribute)attributes.get(i);
> 		writer.attribute(att.getName(), att.getValue());
> 	}
> 	writer.closeTag();
>   }
> }
>
>
> --- Erik Hatcher <er...@ehatchersolutions.com> wrote:
>> How are folks controlling the caching headers (or any other headers
>> for
>> that matter) in the HTTP response from Tapestry applications?
>>
>> I would like to ensure all the caching switches that browsers
>> recognize
>> (including the <meta> pragma one) are set to not cache at all, and in
>>
>> my delving into the Tapestry code and its ResponseOutputStream I
>> don't
>> see a way to add these headers.  Am I missing something?
>>
>> I can get the <meta> one with no problem using the @Shell delegate,
>> though.
>>
>> Should I just use a servlet filter to set these headers?  Or should
>> Tapestry itself allow a way to do this?
>>
>> Thanks,
>> 	Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Controlling HTTP Headers

Posted by Jonny Wray <jo...@yahoo.com>.
I used tapestry directly. Set the delegate attribute of the Shell
component to my specific implementation of IRender. Here's my class:

public class HeaderDelegate implements IRender{
	
  private class Attribute{
    private String name;
    private String value;
		
    public Attribute(String name, String value){
      this.name = name;
      this.value = value;	
    }
		
    public String getName(){
       return name;
    }
		
    public String getValue(){
	return value;
    }
  }
	
  public void render(IMarkupWriter writer, IRequestCycle cycle){
	List attributeList = new ArrayList();
	Attribute att = new Attribute("http-equiv", "Expires");
	attributeList.add(att);
	att = new Attribute("Content", "0");
	attributeList.add(att);
	createMetaTag(writer, attributeList);
		
	attributeList.clear();
	att = new Attribute("http-equiv", "Cache-Control");
	attributeList.add(att);
	att = new Attribute("Content", "must-revalidate, post-check=0,
pre-check=0");
	attributeList.add(att);
	createMetaTag(writer, attributeList);
		
	attributeList.clear();
	att = new Attribute("http-equiv", "Pragma");
	attributeList.add(att);
	att = new Attribute("Content", "public");
	attributeList.add(att);
	createMetaTag(writer, attributeList);
  }
	
  private void createMetaTag(IMarkupWriter writer, List attributes){
	writer.begin("meta");
	for(int i=0;i<attributes.size();i++){
		Attribute att = (Attribute)attributes.get(i);
		writer.attribute(att.getName(), att.getValue());
	}
	writer.closeTag();
  }
}


--- Erik Hatcher <er...@ehatchersolutions.com> wrote:
> How are folks controlling the caching headers (or any other headers
> for 
> that matter) in the HTTP response from Tapestry applications?
> 
> I would like to ensure all the caching switches that browsers
> recognize 
> (including the <meta> pragma one) are set to not cache at all, and in
> 
> my delving into the Tapestry code and its ResponseOutputStream I
> don't 
> see a way to add these headers.  Am I missing something?
> 
> I can get the <meta> one with no problem using the @Shell delegate, 
> though.
> 
> Should I just use a servlet filter to set these headers?  Or should 
> Tapestry itself allow a way to do this?
> 
> Thanks,
> 	Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org