use of com.robo4j.socket.http.HttpMethod in project robo4j by Robo4J.
the class ChannelBufferUtils method extractDecoratedRequestByStringMessage.
/**
* @param message
* message
* @return http decorate request
*/
public static HttpDecoratedRequest extractDecoratedRequestByStringMessage(String message) {
final String[] headerAndBody = message.split(HTTP_HEADER_BODY_DELIMITER);
final String[] header = headerAndBody[POSITION_HEADER].split("[" + HTTP_NEW_LINE + "]+");
final String firstLine = RoboHttpUtils.correctLine(header[0]);
final String[] tokens = firstLine.split(HttpConstant.HTTP_EMPTY_SEP);
final String[] paramArray = Arrays.copyOfRange(header, 1, header.length);
final HttpMethod method = HttpMethod.getByName(tokens[HttpMessageUtils.METHOD_KEY_POSITION]);
final String path = tokens[HttpMessageUtils.URI_VALUE_POSITION];
final String version = tokens[HttpMessageUtils.VERSION_POSITION];
final Map<String, String> headerParams = getHeaderParametersByArray(paramArray);
final HttpRequestDenominator denominator;
if (path.contains(HttpPathUtils.DELIMITER_PATH_ATTRIBUTES)) {
denominator = new HttpRequestDenominator(method, path.split(HttpPathUtils.REGEX_ATTRIBUTE)[0], HttpVersion.getByValue(version), HttpPathUtils.extractAttributesByPath(path));
} else {
denominator = new HttpRequestDenominator(method, path, HttpVersion.getByValue(version));
}
HttpDecoratedRequest result = new HttpDecoratedRequest(headerParams, denominator);
if (headerParams.containsKey(HttpHeaderFieldNames.CONTENT_LENGTH)) {
result.setLength(calculateMessageSize(headerAndBody[POSITION_HEADER].length(), headerParams));
result.addMessage(headerAndBody[POSITION_BODY]);
}
return result;
}
Aggregations