Search in sources :

Example 26 with Http2Request

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

the class IntegColoradoEdu method main.

public static void main(String[] args) throws InterruptedException {
    boolean isHttp = true;
    String host = "www.colorado.edu";
    int port = 443;
    if (isHttp)
        port = 80;
    Http2Request req = createRequest(host);
    log.info("starting socket");
    ChunkedResponseListener listener = new ChunkedResponseListener();
    InetSocketAddress addr = new InetSocketAddress(host, port);
    Http2Socket socket = IntegSingleRequest.createHttpClient("oneTimerHttp2Socket", isHttp, addr);
    socket.connect(addr).thenAccept(socet -> socket.openStream().process(req, listener)).exceptionally(e -> reportException(socket, e));
    Thread.sleep(100000);
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) ResponseStreamHandle(com.webpieces.http2.api.streaming.ResponseStreamHandle) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) XFuture(org.webpieces.util.futures.XFuture) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) PushStreamHandle(com.webpieces.http2.api.streaming.PushStreamHandle) Http2Socket(org.webpieces.http2client.api.Http2Socket) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) InetSocketAddress(java.net.InetSocketAddress) Http2Socket(org.webpieces.http2client.api.Http2Socket)

Example 27 with Http2Request

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

the class Translations2 method translate.

public static HttpFullRequest translate(FullRequest request) {
    // String scheme = request.getHeaders().getScheme();
    Http2Request headers = request.getHeaders();
    String authority = headers.getAuthority();
    String path = headers.getPath();
    String methodString = headers.getMethodString();
    if (methodString == null)
        throw new IllegalArgumentException("http2 :method header is required");
    else if (authority == null) {
        throw new IllegalArgumentException("http1 required host header so http2 message must have :authority header set");
    }
    HttpRequestLine reqLine = new HttpRequestLine();
    reqLine.setUri(new HttpUri(path));
    reqLine.setMethod(new HttpRequestMethod(methodString));
    reqLine.setVersion(new HttpVersion());
    HttpRequest httpReq = new HttpRequest();
    httpReq.setRequestLine(reqLine);
    DataWrapper data = request.getPayload();
    // translate all other headers here as well...
    for (Http2Header header : headers.getHeaders()) {
        if (// All standard headers go elsewhere except HOST which we do below
        !header.getName().startsWith(":"))
            httpReq.addHeader(new Header(header.getName(), header.getValue()));
    }
    httpReq.addHeader(new Header(KnownHeaderName.HOST, authority));
    HttpFullRequest req = new HttpFullRequest(httpReq, data);
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 28 with Http2Request

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

the class ProxyRequestStreamHandle method process.

@Override
public StreamRef process(Http2Request request, ResponseStreamHandle responseListener) {
    ProxyResponseStream proxyResponse = new ProxyResponseStream(responseListener, frontendSocket);
    Map<String, Object> context = Context.copyContext();
    // clear context so server uses a clean context
    Context.restoreContext(new HashMap<>());
    try {
        StreamRef streamRef = stream.incomingRequest(request, proxyResponse);
        return new MockProxyStreamRef(streamRef);
    } finally {
        // client still in this context
        Context.restoreContext(context);
    }
}
Also used : StreamRef(com.webpieces.http2.api.streaming.StreamRef)

Example 29 with Http2Request

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

the class ProxyStreamHandle method createBaseResponse.

@Override
public Http2Response createBaseResponse(Http2Request req, String mimeType, int statusCode, String statusReason) {
    Http2Response response = responseCreator.addCommonHeaders2(req, mimeType, statusCode, statusReason);
    // This is for streaming so set eos=false;
    response.setEndOfStream(false);
    return response;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response)

Example 30 with Http2Request

use of com.webpieces.http2.api.dto.highlevel.Http2Request 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)

Aggregations

Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)71 Test (org.junit.Test)39 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)36 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)36 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)33 StreamRef (com.webpieces.http2.api.streaming.StreamRef)32 DataWrapper (org.webpieces.data.api.DataWrapper)18 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)14 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)14 XFuture (org.webpieces.util.futures.XFuture)13 RequestStreamHandle (com.webpieces.http2.api.streaming.RequestStreamHandle)11 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)10 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)10 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)9 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 InetSocketAddress (java.net.InetSocketAddress)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)7 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)6