Search in sources :

Example 66 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class DefaultCorsProcessor method send403Response.

private void send403Response(ResponseStreamHandle responseStream, Http2Request request) {
    Http2Response response = new Http2Response();
    response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
    response.addHeader(new Http2Header(Http2HeaderName.VARY, "Origin"));
    sendResponse(responseStream, response);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 67 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class InstallSslCertController method modifyResponse.

private Object modifyResponse(Object http2Response) {
    Http2Response resp = (Http2Response) http2Response;
    Http2Header header = resp.getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_TYPE);
    header.setValue("text/plain");
    return resp;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 68 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class JsonController method myStream.

// Method signature cannot have RequestContext since in microservices, we implement an api as the server
// AND a client implements the same api AND client does not have a RequestContext!!
@Override
public StreamRef myStream(ResponseStreamHandle handle2) {
    RouterStreamHandle handle = (RouterStreamHandle) handle2;
    RequestContext requestCtx = Current.getContext();
    Http2Response response = handle.createBaseResponse(requestCtx.getRequest().originalRequest, "text/plain", 200, "Ok");
    response.setEndOfStream(false);
    XFuture<StreamWriter> responseWriter = handle.process(response);
    return new RequestStreamEchoWriter(requestCtx, handle, responseWriter);
}
Also used : RouterStreamHandle(org.webpieces.router.api.RouterStreamHandle) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) RequestContext(org.webpieces.ctx.api.RequestContext)

Example 69 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class Requests method createChunkedResponse.

public static Http2Response createChunkedResponse(int id) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
    headers.add(new Http2Header(Http2HeaderName.SERVER, id + ""));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(false);
    return response;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 70 with Http2Response

use of com.webpieces.http2.api.dto.highlevel.Http2Response in project webpieces by deanhiller.

the class TestC5x1StreamStates method testSection5_1ReceiveValidFramesAfterSendRstStreamFrame.

/**
 * If this state is reached as a result of sending a RST_STREAM frame, the
 * peer that receives the RST_STREAM might have already sent — or enqueued for
 * sending — frames on the stream that cannot be withdrawn. An endpoint MUST ignore
 * frames that it receives on closed streams after it has sent a RST_STREAM frame. An
 * endpoint MAY choose to limit the period over which it ignores frames and
 * treat frames that arrive after this time as being in error.
 * @throws TimeoutException
 * @throws ExecutionException
 * @throws InterruptedException
 */
@Test
public void testSection5_1ReceiveValidFramesAfterSendRstStreamFrame() throws InterruptedException, ExecutionException, TimeoutException {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
    Http2Request request1 = Requests.createRequest();
    RequestStreamHandle stream = httpSocket.openStream();
    StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
    XFuture<StreamWriter> future = streamRef.getWriter();
    @SuppressWarnings("unused") StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(request1, req);
    RstStreamFrame rst = new RstStreamFrame(request1.getStreamId(), Http2ErrorCode.CANCEL);
    XFuture<Void> cancel = streamRef.cancel(rst);
    cancel.get(2, TimeUnit.SECONDS);
    Http2Msg svrRst = mockChannel.getFrameAndClear();
    Assert.assertEquals(rst, svrRst);
    // simulate server responding before receiving the cancel
    Http2Response resp1 = Requests.createEosResponse(request1.getStreamId());
    // endOfStream=true
    mockChannel.write(resp1);
// Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
// Assert.assertFalse(mockChannel.isClosed());
// 
// Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Also used : RequestStreamHandle(com.webpieces.http2.api.streaming.RequestStreamHandle) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamRef(com.webpieces.http2.api.streaming.StreamRef) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) RstStreamFrame(com.webpieces.http2.api.dto.lowlevel.RstStreamFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) Test(org.junit.Test)

Aggregations

Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)66 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)32 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)30 Test (org.junit.Test)30 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)24 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)16 StreamRef (com.webpieces.http2.api.streaming.StreamRef)15 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 DataWrapper (org.webpieces.data.api.DataWrapper)13 Header (org.webpieces.httpparser.api.common.Header)13 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 ArrayList (java.util.ArrayList)10 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)10 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)9 HttpData (org.webpieces.httpparser.api.dto.HttpData)8 XFuture (org.webpieces.util.futures.XFuture)8 RouterService (org.webpieces.router.api.RouterService)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)4