use of com.webpieces.hpack.api.dto.Http2Response in project webpieces by deanhiller.
the class Http2Translations method responseToHeaders.
public static Http2Response responseToHeaders(HttpResponse response) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.STATUS, response.getStatusLine().getStatus().getCode().toString()));
for (Header header : response.getHeaders()) {
if (header.getKnownName() == KnownHeaderName.TRANSFER_ENCODING) {
if ("chunked".equals(header.getValue())) {
//skip as http2 does not allow this header
continue;
}
}
headers.add(new Http2Header(header.getName(), header.getValue()));
}
Http2Response resp = new Http2Response(headers);
Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
if (header != null) {
int len = Integer.parseInt(header.getValue());
if (len == 0) {
resp.setEndOfStream(true);
} else {
resp.setEndOfStream(false);
}
} else {
resp.setEndOfStream(false);
}
return resp;
}
use of com.webpieces.hpack.api.dto.Http2Response in project webpieces by deanhiller.
the class Http2Requests method createResponse.
public static Http2Response createResponse(int streamId, boolean eos) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.SERVER, "id"));
headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
Http2Response response = new Http2Response(headers);
response.setEndOfStream(eos);
response.setStreamId(streamId);
return response;
}
use of com.webpieces.hpack.api.dto.Http2Response in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testPushPromise.
@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Push push = Http2Requests.createPush(request1.getStreamId());
CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushRecv);
Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
pushWriter.processPushResponse(preEmptive);
Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(preEmptive, preEmptRecv);
Http2Response response = Http2Requests.createResponse(request1.getStreamId());
incoming.stream.sendResponse(response);
Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(response, responseRecv);
}
use of com.webpieces.hpack.api.dto.Http2Response in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithNoData.
@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
Http2Request request1 = Http2Requests.createRequest(1, true);
mockChannel.send(request1);
PassedIn incoming = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming.request);
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), true);
incoming.stream.sendResponse(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
}
use of com.webpieces.hpack.api.dto.Http2Response in project webpieces by deanhiller.
the class TestC5_1StreamStates method sendEosResponseFromServer.
private void sendEosResponseFromServer(MockResponseListener listener1, Http2Request request) {
Http2Response resp1 = Requests.createEosResponse(request.getStreamId());
//endOfStream=true
mockChannel.write(resp1);
Http2Response response1 = (Http2Response) listener1.getSingleReturnValueIncomingResponse();
Assert.assertEquals(resp1, response1);
}
Aggregations