Arc90 Wallpapers Theme : Brooklyn, Guns And Technology | Home | Configuring Restlet 1.1 with Spring

Filed under Development on September 15, 2008 by Avi Flax

Custom HTTP Response Headers with Restlet

Our Java apps use the Restlet framework, and we sometimes need to send custom headers in our HTTP responses. This is infrequent enough that we forget how to do so, and need to look it up, but frequent enough that we should really have this snippet close at hand.

So here's how one adds a custom HTTP header to a Restlet Response:

Form responseHeaders = (Form) getResponse().getAttributes().get("org.restlet.http.headers");

if (responseHeaders == null)
{
    responseHeaders = new Form();
    getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}

responseHeaders.add("X-Some-Header", "the value");

Post a Comment Digg Del.icio.us

Trackback Pings (TrackBack URL for this entry)

http://www.arc90.com/cgi-bin/mt4/mt-tb.cgi/191.

Post a Comment:

Arc90 Wallpapers Theme : Brooklyn, Guns And Technology | Main | Configuring Restlet 1.1 with Spring