use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ResponseCreator method createContentResponseImpl.
private ResponseEncodingTuple createContentResponseImpl(Http2Request request, int statusCode, String reason, boolean isDynamicPartOfWebsite, MimeTypeResult mimeType) {
Http2Response response = addCommonHeaders(request, mimeType.mime, isDynamicPartOfWebsite, statusCode, reason);
response.setEndOfStream(false);
response.addHeader(new Http2Header("reason", reason));
return new ResponseEncodingTuple(response, mimeType);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ResponseCreator method addCommonHeaders2.
public Http2Response addCommonHeaders2(Http2Request request, String responseMimeType, int statusCode, String statusReason) {
Http2Response response = new Http2Response();
response.addHeader(new Http2Header(Http2HeaderName.STATUS, statusCode + ""));
if (statusReason != null)
response.addHeader(new Http2Header("reason", statusReason));
String connHeader = request.getSingleHeaderValue(Http2HeaderName.CONNECTION);
String dateStr = DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.now(ZoneOffset.UTC));
Http2Header versionHeader = new Http2Header(Http2HeaderName.SERVER, version);
response.addHeader(versionHeader);
// in general, nearly all these headers are desired..
Http2Header date = new Http2Header(Http2HeaderName.DATE, dateStr);
response.addHeader(date);
if (responseMimeType != null)
response.addHeader(new Http2Header(Http2HeaderName.CONTENT_TYPE, responseMimeType));
if (connHeader == null)
return response;
else if (!"keep-alive".equals(connHeader))
return response;
// just re-use the connHeader from the request...
response.addHeader(request.getHeaderLookupStruct().getHeader(Http2HeaderName.CONNECTION));
return response;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ErrorCommonTest method testRedirectRouteNotEnoughArgumentsBUTwithKeepAlive.
@Test
public void testRedirectRouteNotEnoughArgumentsBUTwithKeepAlive() {
// say method is something(int arg, String this)
// we verify redirects MUST match type and number of method arguments every time
// then when we form url, we put the stuff in the path OR put it as query params so it works on the way back in again too
String moduleFileContents = CommonRoutesModules.class.getName();
RouterService server = createServer(isProdTest, moduleFileContents);
server.start();
Http2Request req = RequestCreation.createHttpRequest(HttpMethod.GET, "/user/5553");
// ADD a keep alive to test keeping alive
req.addHeader(new Http2Header(Http2HeaderName.CONNECTION, "keep-alive"));
MockStreamHandle mockStream = new MockStreamHandle();
StreamRef ref = server.incomingRequest(req, mockStream);
XFuture<StreamWriter> future = ref.getWriter();
Assert.assertTrue(future.isDone() && !future.isCompletedExceptionally());
Http2Response response = mockStream.getLastResponse();
String contents = mockStream.getResponseBody();
Assert.assertEquals(response.getSingleHeaderValue(Http2HeaderName.STATUS), "500");
if (isProdTest) {
Assert.assertTrue(contents.contains("There was a bug in the developers application or webpieces server."));
} else {
// use DevServer template
Assert.assertTrue(contents.contains("NullTemplateApi.java is running for templatePath=org.webpieces.devrouter.impl.internalError_html"));
}
// We did send a keep alive so it should close
Assert.assertFalse(mockStream.isWasClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method fillHeaders.
private void fillHeaders(Http2Response response1) {
String value = "heaheaheaheaheaheahahoz.zhxheh,h,he,he,heaheaeaheaheahoahoahozzoqorqzro.zo.zrszaroatroathoathoathoathoatoh";
for (int i = 0; i < 10; i++) {
value = value + value;
response1.addHeader(new Http2Header("eaheahaheaheaeha" + i, value));
}
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method createInterleavedFrames.
private List<Http2Frame> createInterleavedFrames() {
Http2Response response1 = new Http2Response();
response1.setStreamId(1);
response1.setEndOfStream(true);
fillHeaders(response1);
HeaderEncoding encoding = new HeaderEncoding();
List<Http2Frame> frames1 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response1);
Http2Response response2 = new Http2Response();
response2.setStreamId(3);
response1.setEndOfStream(true);
response2.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "value"));
List<Http2Frame> frames2 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response2);
List<Http2Frame> frames = new ArrayList<>();
frames.addAll(frames1);
frames.add(1, frames2.get(0));
return frames;
}
Aggregations