Search in sources :

Example 1 with ResourceFileDownloadGetHandler

use of com.feeyo.net.http.handler.ResourceFileDownloadGetHandler in project feeyo-hlsserver by variflight.

the class HttpServerRequestHandler method processHttpRequest.

private void processHttpRequest(ChannelHandlerContext ctx, MessageEvent e) {
    HttpRequest request = (DefaultHttpRequest) e.getMessage();
    String uri = request.getUri();
    IRequestHandler requestHandler = getHandler(request);
    if (requestHandler != null) {
        boolean isFilted = requestHandler.isFilted();
        if (isFilted && !processFilter(ctx, e, requestHandler)) {
            IRequestHandler.Type type = requestHandler.getType();
            if (type == IRequestHandler.Type.VM) {
                sendRedirect(ctx, "/v1/view/login");
            } else {
                HttpResponse response = buildDefaultResponse("", HttpResponseStatus.UNAUTHORIZED);
                sendResponse(ctx, response);
            }
            return;
        }
    } else {
        // path 路由不成功, 检测是否是静态文件下载
        int lastDot = uri.lastIndexOf('.');
        if (lastDot != -1) {
            String extension = uri.substring(lastDot + 1).toLowerCase();
            if (extension != null && extension.length() < 6) {
                requestHandler = new ResourceFileDownloadGetHandler();
            }
        }
    }
    if (requestHandler != null) {
        try {
            requestHandler.execute(ctx, e);
        } catch (Exception e1) {
            LOGGER.error("http handler err:", e1);
            HttpResponse response = buildErrorResponse("internal error");
            sendResponse(ctx, response);
        }
    } else {
        HttpResponse response = buildDefaultResponse("", HttpResponseStatus.NOT_FOUND);
        sendResponse(ctx, response);
    }
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) IRequestHandler(com.feeyo.net.http.handler.IRequestHandler) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Type(com.feeyo.net.http.handler.IRequestHandler.Type) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ResourceFileDownloadGetHandler(com.feeyo.net.http.handler.ResourceFileDownloadGetHandler) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

IRequestHandler (com.feeyo.net.http.handler.IRequestHandler)1 Type (com.feeyo.net.http.handler.IRequestHandler.Type)1 ResourceFileDownloadGetHandler (com.feeyo.net.http.handler.ResourceFileDownloadGetHandler)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)1 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)1 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)1 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)1