use of org.jboss.netty.handler.codec.http.HttpMethod in project feeyo-hlsserver by variflight.
the class HttpServerRequestHandler method getHandler.
private IRequestHandler getHandler(HttpRequest request) {
IRequestHandler handler = null;
// 解析QueryString
String uriString = request.getUri();
// 获取Path
String path = null;
int pathEndPos = uriString.indexOf('?');
if (pathEndPos < 0) {
path = uriString;
} else {
path = uriString.substring(0, pathEndPos);
}
// 获取参数
Map<String, String> parameters = new HashMap<String, String>();
if (uriString.startsWith("?")) {
uriString = uriString.substring(1, uriString.length());
}
String[] querys = uriString.split("&");
for (String query : querys) {
String[] pair = query.split("=");
if (pair.length == 2) {
try {
parameters.put(URLDecoder.decode(pair[0], "UTF8"), URLDecoder.decode(pair[1], "UTF8"));
} catch (UnsupportedEncodingException e) {
parameters.put(pair[0], pair[1]);
}
}
}
HttpMethod method = request.getMethod();
if (method == HttpMethod.GET) {
handler = getHandlers.retrieve(path, parameters);
} else if (method == HttpMethod.POST) {
handler = postHandlers.retrieve(path, parameters);
}
return handler;
}
Aggregations