0

Jetty allows headers to be set using the jetty-rewrite functionality, but it doesn't appear to be very smart, and only accepts a fixed string.

How do I tell Jetty to send an "expires in 8 hours" header?

With Apache .htaccess and mod_expires you can do "access plus 8 hours" but of course Jetty doesn't understand .htaccess files, nor can I find any info on a similar construct in jetty-rewrite.xml

<Call name="addRule">
    <Arg>
        <New class="org.eclipse.jetty.rewrite.handler.HeaderPatternRule">
            <Set name="pattern">*.png</Set>
            <Set name="name">Expires</Set>
            <Set name="value">access plus 8 hours</Set>
        </New>
    </Arg>
</Call>

That just sends the literal text "access plus 1 day" back, which is of course ignored by the client.

Could/should this be done with a servlet filter? Jetty has a Gzip filter but doesn't appear to offer something similar for dynamically setting headers.

Peter Boughton
  • 110,170
  • 32
  • 120
  • 176

1 Answers1

1

That could be a nice feature..

Open an enhancement for it at bugs.eclipse.org under RT/Jetty. Patches are welcome, either attached to the bug or pushed into our gerrit instance.

That being said...the jetty xml is really an xml layer over java so I suspect you could actually so this in java if you can find the APi for it. I think there is a joda time library that has a method where you could wire up something that would call new DateTime().plusHours(8) to populate that value.

Probably better to add it as a feature though.

jesse mcconnell
  • 7,102
  • 1
  • 22
  • 33
  • What I'd _really_ like is the ability to process these rules directly in a .htaccess file (so I can use familiar and concise syntax), but I'm guessing there'd be little point in opening an enhancement request for adding htaccess support? – Peter Boughton Aug 27 '12 at 15:11
  • go for it, it would be nice if we had a resource handler that grokked the format...I can't say we'll get to it anytime soon but if its there someone might step up and implement it and contribute :) – jesse mcconnell Aug 27 '12 at 15:22