Search in sources :

Example 1 with HttpUri

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

the class TestUriParsing method testSlash.

@Test
public void testSlash() {
    HttpUri uri = new HttpUri("/");
    UrlInfo urlInfo = uri.getUriBreakdown();
    Assert.assertEquals(null, urlInfo.getPrefix());
    Assert.assertEquals(null, urlInfo.getHost());
    Assert.assertEquals(null, urlInfo.getPort());
    Assert.assertEquals("/", urlInfo.getFullPath());
}
Also used : UrlInfo(org.webpieces.httpparser.api.dto.UrlInfo) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) Test(org.junit.Test)

Example 2 with HttpUri

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

the class HttpParserImpl method parseRequest.

private HttpMessage parseRequest(MementoImpl memento, List<String> lines) {
    //remove first line...
    String firstLine = lines.remove(0);
    String[] firstLinePieces = firstLine.split("\\s+");
    if (firstLinePieces.length != 3) {
        throw new ParseException("Unable to parse invalid http request due to first line being invalid=" + firstLine + " all Lines=" + lines);
    }
    HttpRequestMethod method = new HttpRequestMethod(firstLinePieces[0]);
    HttpUri uri = new HttpUri(firstLinePieces[1]);
    HttpVersion version = parseVersion(firstLinePieces[2], firstLine);
    HttpRequestLine httpRequestLine = new HttpRequestLine();
    httpRequestLine.setMethod(method);
    httpRequestLine.setUri(uri);
    httpRequestLine.setVersion(version);
    HttpRequest request = new HttpRequest();
    request.setRequestLine(httpRequestLine);
    parseHeaders(lines, request);
    memento.addMessage(request);
    return request;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) ParseException(org.webpieces.httpparser.api.ParseException) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 3 with HttpUri

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

the class IntegColoradoEdu method createRequest.

private static HttpRequest createRequest(String host) {
    //		GET / HTTP/1.1
    //		Host: www.colorado.edu
    //		User-Agent: curl/7.43.0
    //		Accept: */*
    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"));
    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 4 with HttpUri

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

the class TestLesson1BasicRequestResponse method createRequest.

static HttpRequest createRequest(String uri) {
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(new HttpUri(uri));
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, "yourdomain.com"));
    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 5 with HttpUri

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

the class Requests method createRequest.

public static HttpRequest createRequest(KnownHttpMethod method, String url, boolean isHttps) {
    HttpUri httpUri = new HttpUri(url);
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(method);
    requestLine.setUri(httpUri);
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
    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) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Aggregations

HttpUri (org.webpieces.httpparser.api.dto.HttpUri)14 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)12 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)12 Header (org.webpieces.httpparser.api.common.Header)9 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3 Test (org.junit.Test)3 DataWrapper (org.webpieces.data.api.DataWrapper)3 HttpData (org.webpieces.httpparser.api.dto.HttpData)3 HttpRequestMethod (org.webpieces.httpparser.api.dto.HttpRequestMethod)2 UrlInfo (org.webpieces.httpparser.api.dto.UrlInfo)2 Http2HeaderStruct (com.webpieces.hpack.api.dto.Http2HeaderStruct)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 Executors (java.util.concurrent.Executors)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 HttpClient (org.webpieces.httpclient.api.HttpClient)1