private StaticFile getStaticPath(String path) { for (StaticFile staticPath : staticPaths) { if (staticPath.isStatic(path)) { return staticPath; } } return null; }
@Override public Response afterUpload(ChannelHandlerContext ctx, String pathToFirmware) { String token = getParam("token"); if (token != null) { log.info("Requested OTA for single device {}.", token); return singleDeviceOTA(ctx, token, pathToFirmware); } String user = getParam("user"); if (user != null) { String appName = getParam("appName"); UserKey userKey = new UserKey(user, appName); String project = getParam("project"); log.info("Requested OTA for single user {}. Project {}.", user, project); return singleUserOTA(ctx, userKey, project, pathToFirmware); } log.info("Requested OTA for all devices..."); return allDevicesOTA(ctx, pathToFirmware); }
private void initHttpPipeline(ChannelHandlerContext ctx) { ctx.pipeline() .addLast(letsEncryptHandler) .addLast("HttpChunkedWrite", new ChunkedWriteHandler()) .addLast("HttpUrlMapper", new UrlReWriterHandler("/favicon.ico", "/static/favicon.ico")) .addLast("HttpStaticFile", new StaticFileHandler(holder.props, new StaticFile("/static"), new StaticFileEdsWith(FileUtils.CSV_DIR, ".gz"), new StaticFileEdsWith(FileUtils.CSV_DIR, ".zip"))) .addLast(resetPasswordLogic) .addLast(httpAPILogic) .addLast(noMatchHandler) .remove(this); if (log.isTraceEnabled()) { log.trace("Initialized http pipeline. {}", ctx.pipeline().names()); } }
private void initAdminPipeline(ChannelHandlerContext ctx) { if (!ipFilterHandler.accept(ctx)) { ctx.close(); return; } var pipeline = ctx.pipeline(); pipeline.addLast(new UploadHandler(holder.props.jarPath, "/upload", "/static/ota")) .addLast(new OTAHandler(holder, rootPath + "/ota/start", "/static/ota")) .addLast(adminAuthHandler) .addLast(authCookieHandler) .addLast(cookieBasedUrlReWriterHandler); pipeline.remove(StaticFileHandler.class); pipeline.addLast(new StaticFileHandler(holder.props, new NoCacheStaticFile("/static"))) .addLast(otaLogic) .addLast(usersLogic) .addLast(statsLogic) .addLast(configsLogic) .addLast(hardwareStatsLogic) .addLast(httpAPILogic) .addLast(noMatchHandler) .remove(this); if (log.isTraceEnabled()) { log.trace("Initialized admin pipeline. {}", ctx.pipeline().names()); } }
private void serveStatic(ChannelHandlerContext ctx, FullHttpRequest request, StaticFile staticFile) throws Exception { if (!request.decoderResult().isSuccess()) { sendError(ctx, BAD_REQUEST); return; String uri = request.uri(); if (isNotSecure(uri)) { sendError(ctx, NOT_FOUND); return; sendError(ctx, NOT_FOUND); return; long fileLastModifiedSeconds = file.lastModified() / 1000; if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) { sendNotModified(ctx); return; raf = new RandomAccessFile(file, "r"); } catch (FileNotFoundException ignore) { sendError(ctx, NOT_FOUND); return; setDateAndCacheHeaders(response, file); if (HttpUtil.isKeepAlive(request)) { response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
HttpRequest req = (HttpRequest) msg; if (!accept(ctx, req)) { ctx.fireChannelRead(msg); return; Response response; try { String path = finishUpload(); if (path != null) { response = afterUpload(ctx, path); } else { response = serverError("Can't find binary data in request.");
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (!(msg instanceof FullHttpRequest)) { return; } FullHttpRequest req = (FullHttpRequest) msg; StaticFile staticFile = getStaticPath(req.uri()); if (staticFile != null) { try { serveStatic(ctx, req, staticFile); } finally { ReferenceCountUtil.release(req); } return; } ctx.fireChannelRead(req); }
var noMatchHandler = new NoMatchHandler(); var webSocketHandler = new WSHandler(stats); var webSocketWrapperEncoder = new WSWrapperEncoder(); var authCookieHandler = new AuthCookieHandler(holder.sessionDao); var cookieBasedUrlReWriterHandler = new CookieBasedUrlReWriterHandler(rootPath, "/static/admin.html", "/static/login.html");
/** * When file timestamp is the same as what the browser is sending up, send a "304 Not Modified" * * @param ctx * Context */ private static void sendNotModified(ChannelHandlerContext ctx) { FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED); setDateHeader(response); // Close the connection as soon as the error message is sent. ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); }
NoMatchHandler noMatchHandler = new NoMatchHandler(); BaseWebSocketUnificator baseWebSocketUnificator = new BaseWebSocketUnificator() { @Override