Search in sources :

Example 36 with Http2Response

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

the class Http2SynchronousClient method startImpl.

public void startImpl(InetSocketAddress svrAddress) throws UnknownHostException, IOException {
    @SuppressWarnings("resource") Socket socket = new Socket(svrAddress.getHostName(), svrAddress.getPort());
    OutputStream output = socket.getOutputStream();
    Runnable client = new ClientWriter(parser, output);
    Thread t1 = new Thread(client);
    t1.setName("clientWriter");
    t1.start();
    InputStream input = socket.getInputStream();
    RateRecorder recorder = new RateRecorder(10);
    while (true) {
        byte[] bytes = new byte[1024];
        int read = input.read(bytes);
        if (read < 0)
            break;
        DataWrapper dataWrapper = dataGen.wrapByteArray(bytes, 0, read);
        UnmarshalState state = parser.unmarshal(dataWrapper);
        List<Http2Msg> messages = state.getParsedFrames();
        // simulate going all the way to http2 like the other test does as well
        for (Http2Msg p : messages) {
            Http2Response resp = (Http2Response) p;
            resp.getStreamId();
            recorder.increment();
        }
    }
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) DataWrapper(org.webpieces.data.api.DataWrapper) RateRecorder(org.webpieces.util.time.RateRecorder) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) Socket(java.net.Socket)

Example 37 with Http2Response

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

the class RequestCreator method createHttp2Response.

public static Http2Response createHttp2Response(int streamId) {
    Http2Response resp = new Http2Response();
    resp.addHeader(new Http2Header(Http2HeaderName.STATUS, "200"));
    resp.addHeader(new Http2Header("serverid", "3"));
    resp.setEndOfStream(true);
    resp.setStreamId(streamId);
    return resp;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 38 with Http2Response

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

the class EchoStreamingClient method stream.

public StreamRef stream(ResponseStreamHandle handle) {
    ProxyStreamHandle h = (ProxyStreamHandle) handle;
    Http2Request req = Current.request().originalRequest;
    Http2Response response = h.createBaseResponse(req, "application/ndjson", 200, "OK");
    try {
        StreamWriter writer = h.process(response).get();
        return new ProxyStreamRef(new EchoWriter(writer));
    } catch (InterruptedException | ExecutionException e) {
        throw SneakyThrow.sneak(e);
    }
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) ProxyStreamHandle(org.webpieces.router.impl.proxyout.ProxyStreamHandle) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) ExecutionException(java.util.concurrent.ExecutionException)

Example 39 with Http2Response

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

the class Requests method createResponse.

public static Http2Response createResponse(int streamId) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, String.valueOf(StatusCode.HTTP_200_OK.getCode())));
    headers.add(new Http2Header(Http2HeaderName.SERVER, "me"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(false);
    response.setStreamId(streamId);
    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 40 with Http2Response

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

the class Requests method createEosResponse.

public static Http2Response createEosResponse(int streamId) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, String.valueOf(StatusCode.HTTP_200_OK.getCode())));
    headers.add(new Http2Header(Http2HeaderName.SERVER, "me"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(true);
    response.setStreamId(streamId);
    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)

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