use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class IntegGoogleHttps method start.
public void start() throws InterruptedException {
log.info("starting test to download / page from google");
boolean isHttp = false;
String host = "www.google.com";
int port = 443;
if (isHttp)
port = 80;
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"));
HttpSocket socket = createSocket(isHttp, host, port);
socket.connect(new InetSocketAddress(host, port)).thenAccept(p -> sendRequest(socket, req)).exceptionally(e -> reportException(socket, e));
Thread.sleep(100000);
}
use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class TestRequestBody method createPostRequestWithBody.
private HttpDummyRequest createPostRequestWithBody() {
byte[] payload = new byte[30];
for (int i = 0; i < payload.length; i++) {
payload[i] = (byte) i;
}
HttpRequest request = TestRequestParsing.createPostRequest();
Header header = new Header();
header.setName(KnownHeaderName.CONTENT_LENGTH);
header.setValue("" + payload.length);
DataWrapper data = dataGen.wrapByteArray(payload);
request.addHeader(header);
HttpData httpData = new HttpData(data, true);
return new HttpDummyRequest(request, httpData);
}
use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class TestRequestParsing method createPostRequest.
static HttpRequest createPostRequest() {
Header header1 = new Header();
header1.setName(KnownHeaderName.ACCEPT);
header1.setValue("CooolValue");
Header header2 = new Header();
//let's keep the case even though name is case-insensitive..
header2.setName("CustomerHEADER");
header2.setValue("betterValue");
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(KnownHttpMethod.POST);
requestLine.setUri(new HttpUri("http://myhost.com"));
HttpRequest request = new HttpRequest();
request.setRequestLine(requestLine);
request.addHeader(header1);
request.addHeader(header2);
return request;
}
use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class TestRequestParsing method testWithHeadersAndBody.
@Test
public void testWithHeadersAndBody() {
HttpRequest request = createPostRequest();
String result1 = request.toString();
String result2 = parser.marshalToString(request);
String msg = "POST http://myhost.com HTTP/1.1\r\n" + "Accept: CooolValue\r\n" + "CustomerHEADER: betterValue\r\n" + "\r\n";
Assert.assertEquals(msg, result1);
Assert.assertEquals(msg, result2);
}
use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class TestRequestParsing method testBasic.
@Test
public void testBasic() {
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(KnownHttpMethod.POST);
requestLine.setUri(new HttpUri("http://myhost.com"));
HttpRequest request = new HttpRequest();
request.setRequestLine(requestLine);
String result1 = request.toString();
String result2 = parser.marshalToString(request);
String msg = "POST http://myhost.com HTTP/1.1\r\n\r\n";
Assert.assertEquals(msg, result1);
Assert.assertEquals(msg, result2);
}
Aggregations