More precisely: I started to make an abstract filter for server-side
handling of Expect-Continue:
@Override protected int beforeHandle(Request request, Response
response) {
for (Expectation expectation :
request.getClientInfo().getExpectations()) {
if (expectation.equals(Expectation.continueResponse())
&& acceptable(request, response)) {
response.setStatus(Status.INFO_CONTINUE);
response.setEntity(new EmptyRepresentation());
} else {
response.setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
response.setEntity(getErrorRepresentation(expectation,
request, response));
}
return Filter.STOP;
}
return Filter.CONTINUE;
}
protected abstract boolean acceptable(Request request, Response
response);
protected Representation getErrorRepresentation(
Expectation expectation, Request request, Response response) {
return new StringRepresentation(
"Server can't meet or does not support expectation: " +
expectation);
}
This appears to work fine when the expectation is not met (acceptable
returns false), but setting status to 100 and setting the entity to an
empty representation doesn't work. The HTTP 1.1
spec<http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3>says
that the server should send a 100 response and continue reading the
input stream, but I don't see a way to do that in basic Restlet terms.
--tim
On Wed, Dec 12, 2012 at 2:20 PM, Tim Peierls <[email protected]> wrote:
> On Wed, Dec 12, 2012 at 11:34 AM, Tim Peierls <[email protected]> wrote:
>
>>
>>> What about the server? How do I hook into it in order to be able to
>>> either
>>> send a 100 or reject the request if it is unable to process it?
>>>
>>
>> I'd start here:
>>
>>
>> http://www.restlet.org/documentation/2.1/jee/api/org/restlet/data/Expectation.html
>>
>
> Hmm, I just tried doing this, and it isn't as straightforward as I
> thought. You'd need to work at the Engine level, and it's not clear that it
> could be done even then.
>
> Hoping a member of the Restlet team will comment.
>
> --tim
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3035238