Hi,
I would like to have your comments about the Asyncweb server API
Actually you create your HttpResponse like that :
MutableHttpResponse response = new DefaultHttpResponse();
response.setContent(myIoBuffer);
response.setHeader("Content-Type", "text/html");
response.setStatus(HttpResponseStatus.OK);
context.commitResponse(response);
I like this API, it's very simple to use. I would like to keep it
because it's *very* easy for anybody to make a simple HttpService for
serving few data, like RPC call or anything you want.
As Dave commented here http://jira.safehaus.org/browse/ASYNCWEB-21 it's
totally inefficient for serving large data and streaming is impossible.
I would like to propose a variation of Dave API idea :
We keep "response.setContent(myIoBuffer);" because it will fit 70% of
the use cases :)
We add to MutableHttpResponse a Queue of IoBuffer you can fill like you
want for example :
MutableHttpResponse response = new DefaultHttpResponse();
response.setStatus(HttpResponseStatus.OK);
response.addContent(buffer1);
response.addContent(buffer2);
response.addContent(buffer3);
response.commitResponse(response);
So you can add content in chunks in place of 1 big buffer, that won't
resolve the streaming problem, but it's convenient.
Now streaming :
MutableHttpResponse response = new DefaultHttpResponse();
response.setStatus(HttpResponseStatus.OK);
// add a first chunk (optional)
response.addContent(buffer1);
PartialResponseListener listener = new PartialResponseListener() {
public void queueEmpty(HTTPResponse response) {
if(moreDataToSend) {
...
// add more data
response.addContent(buffer);
} else {
// streaming is done finish the response
response.done();
}
}
};
response.commitPartialResponse(response, listener);
What I would like to discuss here is to find a good looking API doing
everything you can imagine about streaming (audio,commet,big
files,etc..) before looking at impementation
and of course with good names fitting picky Koreans :)
Julien