use of org.webpieces.httpparser.api.dto.HttpRequestLine 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.HttpRequestLine 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;
}
use of org.webpieces.httpparser.api.dto.HttpRequestLine 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.dto.HttpRequestLine 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.dto.HttpRequestLine in project webpieces by deanhiller.
the class Http2Translations method requestToHeaders.
private static Http2Request requestToHeaders(HttpRequest request, boolean fromSslChannel) {
HttpRequestLine requestLine = request.getRequestLine();
List<Header> requestHeaders = request.getHeaders();
LinkedList<Http2Header> headerList = new LinkedList<>();
// add special headers
headerList.add(new Http2Header(":method", requestLine.getMethod().getMethodAsString()));
UrlInfo urlInfo = requestLine.getUri().getUriBreakdown();
headerList.add(new Http2Header(":path", urlInfo.getFullPath()));
// Figure out scheme
if (urlInfo.getPrefix() != null) {
headerList.add(new Http2Header(":scheme", urlInfo.getPrefix()));
} else if (fromSslChannel) {
headerList.add(new Http2Header(":scheme", "https"));
} else {
headerList.add(new Http2Header(":scheme", "http"));
}
// Figure out authority
Header hostHeader = request.getHeaderLookupStruct().getHeader(KnownHeaderName.HOST);
if (hostHeader == null)
throw new IllegalArgumentException("Host header is required in http1.1");
// Add regular headers
for (Header header : requestHeaders) {
if (header.getKnownName() == KnownHeaderName.HOST) {
//keeps headers in order of http1 headers
String h = hostHeader.getValue();
headerList.add(new Http2Header(":authority", h));
continue;
}
headerList.add(new Http2Header(header.getName().toLowerCase(), header.getValue()));
}
Http2Request headers = new Http2Request(headerList);
Header contentLen = request.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
if (request.isHasChunkedTransferHeader()) {
headers.setEndOfStream(false);
} else if (contentLenGreaterThanZero(contentLen)) {
headers.setEndOfStream(false);
} else
headers.setEndOfStream(true);
return headers;
}
Aggregations