simplified HttpTransport API
This commit is contained in:
parent
e415de44c6
commit
70dafa8eb3
|
@ -49,6 +49,36 @@ public class HttpTransportOverFCGI implements HttpTransport
|
|||
|
||||
@Override
|
||||
public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, Callback callback)
|
||||
{
|
||||
if (info!=null)
|
||||
commit(info,content,lastContent,callback);
|
||||
else
|
||||
{
|
||||
if (head)
|
||||
{
|
||||
if (lastContent)
|
||||
{
|
||||
Generator.Result result = generateResponseContent(BufferUtil.EMPTY_BUFFER, true, callback);
|
||||
flusher.flush(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip content generation
|
||||
callback.succeeded();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Generator.Result result = generateResponseContent(content, lastContent, callback);
|
||||
flusher.flush(result);
|
||||
}
|
||||
|
||||
if (lastContent && shutdown)
|
||||
flusher.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private void commit(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, Callback callback)
|
||||
{
|
||||
boolean head = this.head = info.isHead();
|
||||
boolean shutdown = this.shutdown = info.getHttpFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString());
|
||||
|
@ -78,32 +108,6 @@ public class HttpTransportOverFCGI implements HttpTransport
|
|||
flusher.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ByteBuffer content, boolean lastContent, Callback callback)
|
||||
{
|
||||
if (head)
|
||||
{
|
||||
if (lastContent)
|
||||
{
|
||||
Generator.Result result = generateResponseContent(BufferUtil.EMPTY_BUFFER, true, callback);
|
||||
flusher.flush(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip content generation
|
||||
callback.succeeded();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Generator.Result result = generateResponseContent(content, lastContent, callback);
|
||||
flusher.flush(result);
|
||||
}
|
||||
|
||||
if (lastContent && shutdown)
|
||||
flusher.shutdown();
|
||||
}
|
||||
|
||||
protected Generator.Result generateResponseHeaders(HttpGenerator.ResponseInfo info, Callback callback)
|
||||
{
|
||||
return generator.generateResponseHeaders(request, info.getStatus(), info.getReason(), info.getHttpFields(), callback);
|
||||
|
|
|
@ -85,9 +85,8 @@ public class HttpTransportOverHTTP2 implements HttpTransport
|
|||
HeadersFrame frame = new HeadersFrame(stream.getId(), metaData, null, endStream);
|
||||
stream.headers(frame, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ByteBuffer content, boolean lastContent, Callback callback)
|
||||
|
||||
private void send(ByteBuffer content, boolean lastContent, Callback callback)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
|
@ -98,6 +97,7 @@ public class HttpTransportOverHTTP2 implements HttpTransport
|
|||
stream.data(frame, callback);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void completed()
|
||||
{
|
||||
|
|
|
@ -534,7 +534,7 @@ public class HttpChannel implements Runnable
|
|||
else if (info==null)
|
||||
{
|
||||
// This is a normal write
|
||||
_transport.send(content, complete, callback);
|
||||
_transport.send(null,content, complete, callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -443,13 +443,6 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
|||
_sendCallback.iterate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ByteBuffer content, boolean lastContent, Callback callback)
|
||||
{
|
||||
_sendCallback.reset(null,content,lastContent,callback);
|
||||
_sendCallback.iterate();
|
||||
}
|
||||
|
||||
private class SendCallback extends IteratingCallback
|
||||
{
|
||||
private ResponseInfo _info;
|
||||
|
|
|
@ -26,8 +26,6 @@ import org.eclipse.jetty.util.Callback;
|
|||
public interface HttpTransport
|
||||
{
|
||||
void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, Callback callback);
|
||||
|
||||
void send(ByteBuffer content, boolean lastContent, Callback callback);
|
||||
|
||||
void completed();
|
||||
|
||||
|
|
|
@ -90,12 +90,6 @@ public class ResponseTest
|
|||
{
|
||||
callback.succeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(ByteBuffer responseBodyContent, boolean lastContent, Callback callback)
|
||||
{
|
||||
send(null,responseBodyContent, lastContent, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed()
|
||||
|
|
|
@ -89,14 +89,6 @@ public class HttpTransportOverSPDY implements HttpTransport
|
|||
return requestHeaders;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void send(ByteBuffer responseBodyContent, boolean lastContent, Callback callback)
|
||||
{
|
||||
// TODO can this be more efficient?
|
||||
send(null, responseBodyContent, lastContent, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(HttpGenerator.ResponseInfo info, ByteBuffer content, boolean lastContent, final Callback callback)
|
||||
{
|
||||
|
@ -165,7 +157,6 @@ public class HttpTransportOverSPDY implements HttpTransport
|
|||
}
|
||||
else if (!lastContent && !hasContent && info == null)
|
||||
throw new IllegalStateException("not lastContent, no content and no responseInfo!");
|
||||
|
||||
}
|
||||
|
||||
private void sendReply(HttpGenerator.ResponseInfo info, Callback callback, boolean close)
|
||||
|
|
Loading…
Reference in New Issue