Search in sources :

Example 1 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class TestAjaxHibernate method testAjaxAddUser.

@Test
public void testAjaxAddUser() {
    HttpDummyRequest req = Requests.createPostRequest("/ajax/user/post", "entity.id", "", "entity.name", "blah1", "entity.firstName", "blah2", "password", "asddd");
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Assert.assertEquals("http://myhost.com/ajax/user/list", response.getRedirectUrl());
    Header header = response.createCookieRequestHeader();
    Assert.assertTrue("contents actually was=" + header.getValue(), header.getValue().contains("User+successfully+saved"));
}
Also used : FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 2 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class TestFlashAndSelect method testMultiSelect.

@Test
public void testMultiSelect() {
    HttpDummyRequest req1 = Requests.createPostRequest("/multiselect", "entity.id", user.getId() + "", //invalid first name
    "entity.firstName", //invalid first name
    "NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "", "selectedRoles", "j", "selectedRoles", "d");
    http11Socket.send(req1);
    FullResponse response1 = ResponseExtract.assertSingleResponse(http11Socket);
    response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    String urlPath = "/multiselect/" + user.getId();
    Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    Header cookieHeader = response1.createCookieRequestHeader();
    req.addHeader(cookieHeader);
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("<option value=`b` >Badass</script>".replace('`', '\"'));
    response.assertContains("<option value=`j` selected=`selected`>Jerk</script>".replace('`', '\"'));
    response.assertContains("<option value=`d` selected=`selected`>Delinquint</script>".replace('`', '\"'));
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 3 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class TestFlashAndSelect method testNullWillFlashProperly.

@Test
public void testNullWillFlashProperly() {
    HttpDummyRequest req1 = Requests.createPostRequest("/user/post", "entity.id", user.getId() + "", //invalid first name
    "entity.firstName", //invalid first name
    "NextName", "entity.email", "dean@zz.com", "entity.lastName", "", "entity.password", "", "entity.levelOfEducation", "");
    http11Socket.send(req1);
    FullResponse response1 = ResponseExtract.assertSingleResponse(http11Socket);
    response1.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    String urlPath = "/user/edit/" + user.getId();
    Assert.assertEquals("http://myhost.com" + urlPath, response1.getRedirectUrl());
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, urlPath);
    Header cookieHeader = response1.createCookieRequestHeader();
    req.addHeader(cookieHeader);
    http11Socket.send(req);
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    //assert the nulls came through
    response.assertContains("<input type=`text` name=`entity.lastName` value=`` class=`input-xlarge`>".replace('`', '\"'));
    response.assertContains("<option value=`` selected=`selected`>Unselected</option>".replace('`', '\"'));
    response.assertContains("<option value=`k` >Kindergarten</script>".replace('`', '\"'));
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest) Test(org.junit.Test) WebserverForTest(org.webpieces.webserver.WebserverForTest)

Example 4 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class HttpParserImpl method processHttpMessageAndMaybeBody.

private void processHttpMessageAndMaybeBody(MementoImpl memento, DataWrapper dataToRead, int i) {
    List<Integer> markedPositions = memento.getLeftOverMarkedPositions();
    memento.setLeftOverMarkedPositions(new ArrayList<Integer>());
    List<? extends DataWrapper> tuple = dataGen.split(dataToRead, i + 4);
    DataWrapper toBeParsed = tuple.get(0);
    memento.setLeftOverData(tuple.get(1));
    HttpMessage message = parseHttpMessage(memento, toBeParsed, markedPositions);
    if (memento.isHttp2()) {
        //memento.addMessage(message);
        return;
    }
    Header contentLenHeader = message.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    Header transferHeader = message.getHeaderLookupStruct().getLastInstanceOfHeader(KnownHeaderName.TRANSFER_ENCODING);
    if (transferHeader != null && "chunked".equals(transferHeader.getValue())) {
        memento.setInChunkParsingMode(true);
        processChunks(memento);
        return;
    } else if (contentLenHeader != null && !"0".equals(contentLenHeader.getValue())) {
        String value = contentLenHeader.getValue();
        int length = toInteger(value, "" + contentLenHeader);
        memento.setContentLengthLeftToRead(length);
        readInContentLengthBody(memento);
        return;
    }
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpMessage(org.webpieces.httpparser.api.dto.HttpMessage)

Example 5 with Header

use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.

the class HttpParserImpl method parseHeaders.

private void parseHeaders(List<String> lines, HttpMessage httpMessage) {
    //ie. the spec says you can split a head in multiple lines(ick!!!)
    for (String line : lines) {
        Header header = parseHeader(line);
        httpMessage.addHeader(header);
    }
}
Also used : Header(org.webpieces.httpparser.api.common.Header)

Aggregations

Header (org.webpieces.httpparser.api.common.Header)64 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)32 Test (org.junit.Test)24 DataWrapper (org.webpieces.data.api.DataWrapper)18 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)16 FullResponse (org.webpieces.webserver.test.FullResponse)16 AbstractWebpiecesTest (org.webpieces.webserver.test.AbstractWebpiecesTest)13 WebserverForTest (org.webpieces.webserver.WebserverForTest)12 HttpData (org.webpieces.httpparser.api.dto.HttpData)11 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)10 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)10 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)10 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)9 HttpDummyRequest (org.webpieces.webserver.test.HttpDummyRequest)9 Http2Response (com.webpieces.hpack.api.dto.Http2Response)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)7 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)7 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)5 HttpResponseStatus (org.webpieces.httpparser.api.dto.HttpResponseStatus)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4