Search in sources :

Example 51 with Header

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

the class FullResponse method assertContentType.

public void assertContentType(String mimeType) {
    Header type = getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_TYPE);
    String value = type.getValue();
    if (!mimeType.equals(value))
        throw new IllegalStateException("Expected mimeType=" + mimeType + " but found type=" + value);
}
Also used : Header(org.webpieces.httpparser.api.common.Header)

Example 52 with Header

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

the class TestFlashAndSelect method testMultiSelectSingleSelection.

@Test
public void testMultiSelectSingleSelection() {
    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");
    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` >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 53 with Header

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

the class TestAsyncHibernate method saveBean.

private String saveBean(String path) {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.POST, path);
    http11Socket.send(req);
    List<FullResponse> responses1 = http11Socket.getResponses();
    Assert.assertEquals(0, responses1.size());
    List<Runnable> runnables = mockExecutor.getRunnablesScheduled();
    runnables.get(0).run();
    mockExecutor.clear();
    FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
    response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
    Header header = response.getResponse().getHeaderLookupStruct().getHeader(KnownHeaderName.LOCATION);
    String url = header.getValue();
    return url;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) FullResponse(org.webpieces.webserver.test.FullResponse) Header(org.webpieces.httpparser.api.common.Header)

Example 54 with Header

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

the class Requests method createJsonRequest.

public static HttpDummyRequest createJsonRequest(KnownHttpMethod method, String url) {
    HttpRequest request = createRequest(method, url);
    String json = "{ `query`: `cats and dogs`, `meta`: { `numResults`: 4 } }".replace("`", "\"");
    DataWrapper body = gen.wrapByteArray(json.getBytes());
    HttpData data = new HttpData(body, true);
    request.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
    return new HttpDummyRequest(request, data);
}
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) HttpDummyRequest(org.webpieces.webserver.test.HttpDummyRequest)

Example 55 with Header

use of org.webpieces.httpparser.api.common.Header 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)

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