Search in sources :

Example 26 with Http2Header

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);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 27 with Http2Header

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;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 28 with Http2Header

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());
}
Also used : RouterService(org.webpieces.router.api.RouterService) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Test(org.junit.Test)

Example 29 with Http2Header

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));
    }
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 30 with Http2Header

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;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) HeaderEncoding(com.webpieces.hpack.impl.HeaderEncoding) Encoder(com.twitter.hpack.Encoder) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Aggregations

Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)72 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)26 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)23 ArrayList (java.util.ArrayList)23 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 XFuture (org.webpieces.util.futures.XFuture)7 InetSocketAddress (java.net.InetSocketAddress)6 Header (org.webpieces.httpparser.api.common.Header)6 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)5 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)5 List (java.util.List)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ResponseStreamHandle (com.webpieces.http2.api.streaming.ResponseStreamHandle)4 Executor (java.util.concurrent.Executor)4 Executors (java.util.concurrent.Executors)4