use of org.webpieces.httpparser.api.ParseException in project webpieces by deanhiller.
the class ParserUtil method parseVersion.
public HttpVersion parseVersion(String versionString, String firstLine) {
if (!versionString.startsWith("HTTP/")) {
throw new ParseException("Invalid version in http request first line not prefixed with HTTP/. line=" + firstLine);
}
String ver = versionString.substring(5, versionString.length());
HttpVersion version = new HttpVersion();
version.setVersion(ver);
return version;
}
use of org.webpieces.httpparser.api.ParseException 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 = parserUtil.parseVersion(firstLinePieces[2], firstLine);
HttpRequestLine httpRequestLine = new HttpRequestLine();
httpRequestLine.setMethod(method);
httpRequestLine.setUri(uri);
httpRequestLine.setVersion(version);
HttpRequest request = new HttpRequest();
request.setRequestLine(httpRequestLine);
parserUtil.parseHeaders(lines, request);
memento.addMessage(request);
return request;
}
use of org.webpieces.httpparser.api.ParseException in project webpieces by deanhiller.
the class HttpParserImpl method parseVersion.
private HttpVersion parseVersion(String versionString, String firstLine) {
if (!versionString.startsWith("HTTP/")) {
throw new ParseException("Invalid version in http request first line not prefixed with HTTP/. line=" + firstLine);
}
String ver = versionString.substring(5, versionString.length());
HttpVersion version = new HttpVersion();
version.setVersion(ver);
return version;
}
Aggregations