use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class ResponseCreator method addCommonHeaders.
public Http2Response addCommonHeaders(Http2Request request, String responseMimeType, boolean isDynamicPartOfWebsite, int statusCode, String statusReason) {
Http2Response response = addCommonHeaders2(request, responseMimeType, statusCode, statusReason);
boolean isInternalError = statusCode >= 500 && statusCode < 600;
if (isDynamicPartOfWebsite) {
List<RouterCookie> cookies = createCookies(isInternalError);
for (RouterCookie c : cookies) {
Http2Header cookieHeader = create(c);
response.addHeader(cookieHeader);
}
}
return response;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request 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());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method testSection4_3BadDecompression.
// /**
// * A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
// *
// */
@Test
public void testSection4_3BadDecompression() {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
Http2Request request = sendRequestToServer(listener1);
// has to be 1 since we use 1 in the response
Assert.assertEquals(1, request.getStreamId());
String badHeaderFrame = // length
"00 00 10" + // type
"01" + // flags (ack)
"05" + // R + streamid
"00 00 00 01" + // payload
"00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00";
// endOfStream=false
mockChannel.writeHexBack(badHeaderFrame);
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.COMPRESSION_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(HEADER_DECODE) Error from hpack library", msg);
Assert.assertTrue(mockChannel.isClosed());
List<CancelReason> results = listener1.getRstStreams();
Assert.assertEquals(1, results.size());
ShutdownStream failResp = (ShutdownStream) results.get(0);
Assert.assertEquals(CancelReasonCode.HEADER_DECODE, failResp.getCause().getReasonCode());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestCMaxConcurrentSetting method sendTwoRequests.
private RequestsSent sendTwoRequests() {
Http2Request request1 = Requests.createRequest();
Http2Request request2 = Requests.createRequest();
MockStreamWriter writer1 = new MockStreamWriter();
MockStreamWriter writer2 = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.completedFuture(writer1));
// do not set default incoming response as we want to delay the resolution of the future
MockResponseListener listener2 = new MockResponseListener();
StreamRef streamRef1 = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef1.getWriter();
StreamRef streamRef2 = httpSocket.openStream().process(request2, listener2);
XFuture<StreamWriter> future2 = streamRef2.getWriter();
RequestHolder r1 = new RequestHolder(request1, listener1, writer1, future);
RequestHolder r2 = new RequestHolder(request2, listener2, writer2, future2);
RequestsSent requests = new RequestsSent(r1, r2);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(1, req.getStreamId());
Assert.assertEquals(request1, req);
Assert.assertTrue(future.isDone());
Assert.assertFalse(future2.isDone());
return requests;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class Requests method createRequest.
static Http2Request createRequest(boolean eos) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
headers.add(new Http2Header(Http2HeaderName.AUTHORITY, "somehost.com"));
headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
headers.add(new Http2Header(Http2HeaderName.SCHEME, "http"));
headers.add(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
headers.add(new Http2Header(Http2HeaderName.ACCEPT_ENCODING, "gzip, deflate"));
headers.add(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/1.15.0"));
Http2Request request = new Http2Request(headers);
request.setEndOfStream(eos);
return request;
}
Aggregations