use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class TestSyncHibernate method saveBean.
private String saveBean(String path) {
HttpRequest req = Requests.createRequest(KnownHttpMethod.POST, path);
http11Socket.send(req);
FullResponse response = ResponseExtract.assertSingleResponse(http11Socket);
response.assertStatusCode(KnownStatusCode.HTTP_303_SEEOTHER);
return response.getRedirectUrl();
}
use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class IntegColoradoEdu method main.
public static void main(String[] args) {
boolean isHttp = false;
String host = "www.colorado.edu";
int port = 443;
if (isHttp)
port = 80;
HttpRequest req = createRequest(host);
log.info("starting socket");
ChunkedResponseListener listener = new ChunkedResponseListener();
HttpSocket socket = IntegGoogleHttps.createSocket(isHttp, host, port);
socket.connect(new InetSocketAddress(host, port)).thenAccept(p -> socket.send(req, listener)).exceptionally(e -> reportException(socket, e));
}
use of org.webpieces.httpparser.api.dto.HttpRequest 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;
}
use of org.webpieces.httpparser.api.dto.HttpRequest in project webpieces by deanhiller.
the class TestRequestBody method testPartialBody.
@Test
public void testPartialBody() {
HttpDummyRequest request = createPostRequestWithBody();
byte[] expected = request.getHttpData().getBody().createByteArray();
byte[] data = unwrap(request);
byte[] first = new byte[data.length - 20];
byte[] second = new byte[data.length - first.length];
System.arraycopy(data, 0, first, 0, first.length);
System.arraycopy(data, first.length, second, 0, second.length);
DataWrapper wrap1 = dataGen.wrapByteArray(first);
DataWrapper wrap2 = dataGen.wrapByteArray(second);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, wrap1);
Assert.assertEquals(ParsingState.BODY, memento.getUnParsedState().getCurrentlyParsing());
Assert.assertEquals(0, memento.getUnParsedState().getCurrentUnparsedSize());
HttpRequest httpRequest = memento.getParsedMessages().get(0).getHttpRequest();
Assert.assertEquals(request.getRequest(), httpRequest);
HttpData data1 = memento.getParsedMessages().get(1).getHttpData();
Assert.assertEquals(2, memento.getParsedMessages().size());
memento = parser.parse(memento, wrap2);
Assert.assertEquals(1, memento.getParsedMessages().size());
HttpData data2 = memento.getParsedMessages().get(0).getHttpData();
DataWrapper body = dataGen.chainDataWrappers(data1.getBody(), data2.getBody());
byte[] bodyBytesActual = body.createByteArray();
Assert.assertArrayEquals(expected, bodyBytesActual);
}
use of org.webpieces.httpparser.api.dto.HttpRequest 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;
}
Aggregations