Restlet provides the 304 plumbing for you. Just setModificationDate() on your Resource's returned Representation as Jon suggests. The GET headers returned from my Web site which calls this function are below. If you hit this resource with Firefox and watch it with Firebug as you refresh (which does conditional GETs), you'll see 304s being returned instead. This is all done by Restlet internally -- my code doesn't know anything about conditional processing.
curl -I http://solertium.com/index.html HTTP/1.1 200 OK Expires: Wed, 10 Jun 2009 15:55:42 GMT Content-Type: text/html; charset=UTF-8 Last-Modified: Wed, 10 Jun 2009 15:40:42 GMT Content-Length: 11302 Date: Wed, 10 Jun 2009 15:40:42 GMT Set-Cookie: BROWSERID=cQv0DC1n-c0fgM3-Jl; Path=/; HttpOnly Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept Server: Noelios-Restlet-Engine/1.2.m1 On Wed, Jun 10, 2009 at 11:36 AM, Sherif Ahmed <sherifah...@hotmail.com>wrote: > Thanks Jon. > > What I am trying to accomplish is implementing the Last-Modified / > If-Modified-Since logic. Where I would tag responses with a uniform > "Last-Modified" header for all resources/representations and when a request > comes in with a "If-Modified-Since" header I'd send appropriate HTTP 304 > response or completely process the response. > > Ideas/Best Practices to accomplish this without having to get the > HttpServletRequest/Response objects to do this would be great > > > Hi Sherif, > > > > For custom headers whatever name you give, "entity.modificationDate", > > will be used. > > > > However, what you probably meant to do is use setModificationDate(new > > Date()) on the entity/response representation. ie. > > representation.setModificationDate(new Date()); > > > > Jon > > > > Sherif Ahmed wrote: > > > I've been trying to add Last-Modified Header via the following code in > a Filter afterHandle method > > > > > > Form responseHeaders = (Form) > response.getAttributes().get("org.restlet.http.headers"); > > > > > > if (responseHeaders == null) > > > { > > > responseHeaders = new Form(); > > > response.getAttributes().put("org.restlet.http.headers", > responseHeaders); > > > } > > > responseHeaders.add("entity.modificationDate", "Sun, 06 Nov 2005 > 14:59:42 GMT"); > > > > > > > > > However the header in the HTTP Response is not "Last-Modified" as I > would have expected, rather a custom header > > > > > > "entity.modificationDate: Sun, 06 Nov 2005 14:59:42 GMT" > > > > > > Quick response would be much appreciated > > > > > > ------------------------------------------------------ > > > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2360858 > > > > > ------------------------------------------------------ > > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2360959 > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2360964