use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class NullWriter method processPiece.
@Override
public XFuture<Void> processPiece(StreamMsg data) {
DataFrame f = (DataFrame) data;
DataWrapper body = f.getData();
String str = body.createStringFromUtf8(0, body.getReadableSize());
log.error("Should not be receiving data(len=" + body.getReadableSize() + "). data Received=" + str, new RuntimeException("Received data here and should not").fillInStackTrace());
return XFuture.completedFuture(null);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class XFileReader method sendHttpChunk.
private XFuture<Void> sendHttpChunk(StreamWriter writer, BufferPool pool, ByteBuffer buf, boolean isEos) {
DataWrapper data = wrapperFactory.wrapByteBuffer(buf);
int len = data.getReadableSize();
if (log.isTraceEnabled())
log.trace("SENDING data to=" + writer + " len=" + len + " isEnd=" + isEos + " content=" + data.createStringFromUtf8(0, len));
DataFrame frame = new DataFrame();
frame.setEndOfStream(isEos);
frame.setData(data);
return writer.processPiece(frame).thenApply(w -> {
// at this point, the buffer was consumed
// after process, release the buffer for re-use
buf.position(buf.limit());
pool.releaseBuffer(buf);
return null;
});
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class ProxyStreamHandle method createFrame.
private CompletionStage<Void> createFrame(byte[] bytes, StreamWriter writer) {
DataFrame frame = new DataFrame();
frame.setEndOfStream(true);
frame.setData(dataGen.wrapByteArray(bytes));
return writer.processPiece(frame);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class RequestStreamWriter2 method processPiece.
@Override
public XFuture<Void> processPiece(StreamMsg frame) {
if (cancelled) {
return XFuture.completedFuture(null);
} else if (frame instanceof CancelReason) {
cancelled = true;
responseFuture.cancel(true);
} else if (frame instanceof DataFrame) {
DataFrame dataFrame = (DataFrame) frame;
data = dataGen.chainDataWrappers(data, dataFrame.getData());
} else if (frame instanceof Http2Headers) {
if (!frame.isEndOfStream())
throw new IllegalArgumentException("Trailing headers from client must have end of stream set");
trailingHeaders = (Http2Headers) frame;
} else {
throw new IllegalStateException("frame not expected=" + frame);
}
if (frame.isEndOfStream()) {
return handleCompleteRequestImpl();
}
// return immediately resolved as we need more data to form request
return XFuture.completedFuture(null);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method testSection4_2CanSendLargestFrame.
/**
* success case of edge testing off by one or not
*/
@Test
public void testSection4_2CanSendLargestFrame() {
MockStreamWriter mockStreamWriter = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
Http2Request request = sendRequestToServer(listener1);
sendResponseFromServer(listener1, request);
DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
byte[] buf = new byte[localSettings.getMaxFrameSize()];
dataFrame.setData(DATA_GEN.wrapByteArray(buf));
// endOfStream=false
mockChannel.write(dataFrame);
DataFrame fr = (DataFrame) mockStreamWriter.getSingleFrame();
Assert.assertEquals(localSettings.getMaxFrameSize(), fr.getData().getReadableSize());
}
Aggregations