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