Search in sources :

Example 11 with HttpRequestLine

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

the class Requests method createRequest.

public static HttpRequest createRequest(KnownHttpMethod method, String url, Integer port) {
    HttpUri httpUri = new HttpUri(url);
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(method);
    requestLine.setUri(httpUri);
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    if (port == null)
        req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
    else
        req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com:" + port));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 12 with HttpRequestLine

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

the class Requests method createPostRequestImpl.

private static HttpDummyRequest createPostRequestImpl(String url, String... argTuples) throws UnsupportedEncodingException {
    if (argTuples.length % 2 != 0)
        throw new IllegalArgumentException("argTuples.length must be of even size (key/value)");
    HttpUri httpUri = new HttpUri(url);
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.POST);
    requestLine.setUri(httpUri);
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
    String encodedParams = "";
    for (int i = 0; i < argTuples.length; i += 2) {
        String key = URLEncoder.encode(argTuples[i], StandardCharsets.UTF_8);
        String value = URLEncoder.encode(argTuples[i + 1], StandardCharsets.UTF_8);
        if (!"".equals(encodedParams))
            encodedParams += "&";
        encodedParams += key + "=" + value;
    }
    byte[] bytes = encodedParams.getBytes(StandardCharsets.UTF_8);
    DataWrapper body = gen.wrapByteArray(bytes);
    HttpData data = new HttpData(body, true);
    req.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "" + body.getReadableSize()));
    req.addHeader(new Header(KnownHeaderName.CONTENT_TYPE, "application/x-www-form-urlencoded"));
    return new HttpDummyRequest(req, data);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 13 with HttpRequestLine

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

the class Requests method createGetRequest.

public static HttpRequest createGetRequest(String domain, String url) {
    HttpUri httpUri = new HttpUri(url);
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(httpUri);
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, domain));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Aggregations

HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)13 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)12 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)12 Header (org.webpieces.httpparser.api.common.Header)10 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)4 DataWrapper (org.webpieces.data.api.DataWrapper)3 HttpData (org.webpieces.httpparser.api.dto.HttpData)3 HttpRequestMethod (org.webpieces.httpparser.api.dto.HttpRequestMethod)2 Http2HeaderStruct (com.webpieces.hpack.api.dto.Http2HeaderStruct)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Executor (java.util.concurrent.Executor)1 Executors (java.util.concurrent.Executors)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)1 BufferPool (org.webpieces.data.api.BufferPool)1