Search in sources :

Example 86 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class IntegGoogleHttps method start.

public void start() throws InterruptedException {
    log.info("starting test to download / page from google");
    boolean isHttp = false;
    String host = "www.google.com";
    int port = 443;
    if (isHttp)
        port = 80;
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(new HttpUri("/"));
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, host));
    req.addHeader(new Header(KnownHeaderName.ACCEPT, "*/*"));
    req.addHeader(new Header(KnownHeaderName.USER_AGENT, "webpieces/0.9"));
    HttpSocket socket = createSocket(isHttp, host, port);
    socket.connect(new InetSocketAddress(host, port)).thenAccept(p -> sendRequest(socket, req)).exceptionally(e -> reportException(socket, e));
    Thread.sleep(100000);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) BufferPool(org.webpieces.data.api.BufferPool) LoggerFactory(org.slf4j.LoggerFactory) ChannelManager(org.webpieces.nio.api.ChannelManager) HttpResponseListener(org.webpieces.httpclient.api.HttpResponseListener) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpParserFactory(org.webpieces.httpparser.api.HttpParserFactory) Header(org.webpieces.httpparser.api.common.Header) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) HttpClient(org.webpieces.httpclient.api.HttpClient) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) HttpParser(org.webpieces.httpparser.api.HttpParser) KnownHeaderName(org.webpieces.httpparser.api.common.KnownHeaderName) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) HttpClientFactory(org.webpieces.httpclient.api.HttpClientFactory) HttpSocket(org.webpieces.httpclient.api.HttpSocket) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) KnownHttpMethod(org.webpieces.httpparser.api.dto.KnownHttpMethod) HttpSocket(org.webpieces.httpclient.api.HttpSocket) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) InetSocketAddress(java.net.InetSocketAddress) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 87 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestRequestBody method createPostRequestWithBody.

private HttpDummyRequest createPostRequestWithBody() {
    byte[] payload = new byte[30];
    for (int i = 0; i < payload.length; i++) {
        payload[i] = (byte) i;
    }
    HttpRequest request = TestRequestParsing.createPostRequest();
    Header header = new Header();
    header.setName(KnownHeaderName.CONTENT_LENGTH);
    header.setValue("" + payload.length);
    DataWrapper data = dataGen.wrapByteArray(payload);
    request.addHeader(header);
    HttpData httpData = new HttpData(data, true);
    return new HttpDummyRequest(request, httpData);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpData(org.webpieces.httpparser.api.dto.HttpData)

Example 88 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestRequestParsing method createPostRequest.

static HttpRequest createPostRequest() {
    Header header1 = new Header();
    header1.setName(KnownHeaderName.ACCEPT);
    header1.setValue("CooolValue");
    Header header2 = new Header();
    //let's keep the case even though name is case-insensitive..
    header2.setName("CustomerHEADER");
    header2.setValue("betterValue");
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.POST);
    requestLine.setUri(new HttpUri("http://myhost.com"));
    HttpRequest request = new HttpRequest();
    request.setRequestLine(requestLine);
    request.addHeader(header1);
    request.addHeader(header2);
    return request;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Header(org.webpieces.httpparser.api.common.Header) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 89 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestRequestParsing method testWithHeadersAndBody.

@Test
public void testWithHeadersAndBody() {
    HttpRequest request = createPostRequest();
    String result1 = request.toString();
    String result2 = parser.marshalToString(request);
    String msg = "POST http://myhost.com HTTP/1.1\r\n" + "Accept: CooolValue\r\n" + "CustomerHEADER: betterValue\r\n" + "\r\n";
    Assert.assertEquals(msg, result1);
    Assert.assertEquals(msg, result2);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Test(org.junit.Test)

Example 90 with HttpRequest

use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.

the class TestRequestParsing method testBasic.

@Test
public void testBasic() {
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.POST);
    requestLine.setUri(new HttpUri("http://myhost.com"));
    HttpRequest request = new HttpRequest();
    request.setRequestLine(requestLine);
    String result1 = request.toString();
    String result2 = parser.marshalToString(request);
    String msg = "POST http://myhost.com HTTP/1.1\r\n\r\n";
    Assert.assertEquals(msg, result1);
    Assert.assertEquals(msg, result2);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) Test(org.junit.Test)

Aggregations

HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)157 Test (org.junit.Test)136 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)120 FullResponse (org.webpieces.webserver.test.FullResponse)120 WebserverForTest (org.webpieces.webserver.WebserverForTest)114 Header (org.webpieces.httpparser.api.common.Header)33 DataWrapper (org.webpieces.data.api.DataWrapper)17 PlatformOverridesForTest (org.webpieces.webserver.test.PlatformOverridesForTest)15 HttpData (org.webpieces.httpparser.api.dto.HttpData)13 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)13 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)13 CompletableFuture (java.util.concurrent.CompletableFuture)11 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)8 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)8 Http2Response (com.webpieces.hpack.api.dto.Http2Response)6 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)6 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 StreamWriter (com.webpieces.http2engine.api.StreamWriter)3 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3