Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to construct message header for a HEAD response with restlet
    primarykey
    data
    text
    <p>I'm trying to create a HEAD response with restlet. Unfortunatly there is ony a <code>@Get</code> annotation, but the restlet author <a href="http://markmail.org/message/65xfouswij67teh5" rel="nofollow">states</a>, that you have to use a <code>@Get</code>, and then compare the Method. As the <a href="http://www.restlet.org/documentation/2.0/jse/api/org/restlet/data/Method.html#HEAD" rel="nofollow">documentation/specification</a> says, there can be no body, but only a message header.</p> <p>Now how to create a message header that will be send to the server, because the following code does not work, it sends this headers: HTTP/1.1 204 No Content, Content-Length: 0</p> <pre><code>protected void addResponseHeader(String name, String value) { Form responseHeaders = (Form)getResponse().getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS); if (responseHeaders == null) { responseHeaders = new Form(); getResponse().getAttributes().put(HeaderConstants.ATTRIBUTE_HEADERS, responseHeaders); } responseHeaders.add(new Parameter(name, value)); } </code></pre> <p>The concrete code on server-side:</p> <pre><code>@Get public void execute() { if (Method.HEAD.equals(getMethod())) { //optional: getResponse().getEntity().setMediaType(MediaType.TEXT_PLAIN); getResponse().setStatus(Status.SUCCESS_OK, "hello head"); addResponseHeader("X-my-header", "value"); } } </code></pre> <p>The client code:</p> <pre><code>@Test public void head() { Request request = new Request(Method.HEAD, url); Response response = query(request); assertEquals(Status.SUCCESS_OK, response.getStatus()); Form form = (Form)response.getAttributes().get(HeaderConstants.ATTRIBUTE_HEADERS); assertEquals("value", form.getFirstValue("X-my-value")); // does fail because it is null } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload