use of org.webpieces.httpparser.api.common.Header 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;
}
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, 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;
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class Requests method createNobodyResponse.
public static HttpResponse createNobodyResponse() {
HttpResponseStatus status = new HttpResponseStatus();
status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse resp = new HttpResponse();
resp.setStatusLine(statusLine);
resp.addHeader(new Header(KnownHeaderName.CONNECTION, "keep"));
resp.addHeader(new Header(KnownHeaderName.AGE, "hh"));
resp.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
return resp;
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class Requests method createResponse.
public static HttpResponse createResponse(int id) {
HttpResponseStatus status = new HttpResponseStatus();
status.setKnownStatus(KnownStatusCode.HTTP_200_OK);
HttpResponseStatusLine statusLine = new HttpResponseStatusLine();
statusLine.setStatus(status);
HttpResponse resp = new HttpResponse();
resp.setStatusLine(statusLine);
resp.addHeader(new Header("Server", id + ""));
resp.addHeader(new Header(KnownHeaderName.CONNECTION, "keep"));
resp.addHeader(new Header(KnownHeaderName.AGE, "hh"));
return resp;
}
use of org.webpieces.httpparser.api.common.Header in project webpieces by deanhiller.
the class TestHttp11Basic method testSendTwoRequestsStreamFirstResponse.
@Test
public void testSendTwoRequestsStreamFirstResponse() throws InterruptedException, ExecutionException, TimeoutException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
mockChannel.write(req);
PassedIn in1 = mockListener.getSingleRequest();
mockChannel.write(req2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "10"));
Http2Response headers1 = Http2Translations.responseToHeaders(resp1);
CompletableFuture<StreamWriter> future = in1.stream.sendResponse(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
byte[] buf = new byte[10];
DataWrapper dataWrapper = dataGen.wrapByteArray(buf);
HttpData data1 = new HttpData(dataWrapper, true);
DataFrame data = (DataFrame) Http2Translations.translateData(data1);
writer.processPiece(data);
HttpData d = (HttpData) mockChannel.getFrameAndClear();
Assert.assertEquals(10, d.getBody().getReadableSize());
PassedIn in2 = mockListener.getSingleRequest();
HttpResponse resp2 = Requests.createResponse(2);
resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers2 = Http2Translations.responseToHeaders(resp2);
in2.stream.sendResponse(headers2);
HttpPayload payload2 = mockChannel.getFrameAndClear();
Assert.assertEquals(resp2, payload2);
}
Aggregations