use of org.webpieces.httpparser.api.dto.HttpRequestMethod 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.HttpRequestMethod in project webpieces by deanhiller.
the class Http2Translations method translateRequest.
public static HttpRequest translateRequest(Http2Request headers) {
HttpRequestLine requestLine = new HttpRequestLine();
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
for (Http2Header header : headers.getHeaders()) {
insertInfo(req, header);
}
Http2HeaderStruct headerMap = headers.getHeaderLookupStruct();
Http2Header method = headerMap.getHeader(Http2HeaderName.METHOD);
if (method == null)
throw new IllegalArgumentException(Http2HeaderName.METHOD.name() + "is a required header to translate to http1");
req.getRequestLine().setMethod(new HttpRequestMethod(method.getValue()));
Http2Header host = headerMap.getHeader(Http2HeaderName.AUTHORITY);
if (host == null)
throw new IllegalArgumentException(Http2HeaderName.AUTHORITY.name() + "is a required header to translate to http1");
Http2Header path = headerMap.getHeader(Http2HeaderName.PATH);
if (path == null)
throw new IllegalArgumentException(Http2HeaderName.PATH.name() + "is a required header to translate to http1");
HttpUri httpUri = new HttpUri(path.getValue());
req.getRequestLine().setUri(httpUri);
return req;
}
Aggregations