/* Set the fileHandler as the selected handler for the request */ PUBLIC void httpSetFileHandler(HttpConn *conn, cchar *path) { HttpStage *fp; HttpTx *tx; tx = conn->tx; if (path && path != tx->filename) { httpSetFilename(conn, path, 0); } if ((conn->rx->flags & HTTP_GET) && !(tx->flags & HTTP_TX_HAS_FILTERS) && !conn->secure && !httpTracing(conn)) { tx->flags |= HTTP_TX_SENDFILE; tx->connector = HTTP->sendConnector; } tx->entityLength = tx->fileInfo.size; fp = tx->handler = HTTP->fileHandler; fp->open(conn->writeq); fp->start(conn->writeq); conn->writeq->service = fp->outgoingService; conn->readq->put = fp->incoming; }
PUBLIC bool espRenderView(HttpConn *conn, cchar *target, int flags) { HttpRx *rx; HttpRoute *route; EspRoute *eroute; EspViewProc viewProc; rx = conn->rx; route = rx->route; eroute = route->eroute; #if !ME_STATIC if (!eroute->combine && (route->update || !mprLookupKey(eroute->top->views, target))) { cchar *errMsg; /* WARNING: GC yield */ target = sclone(target); mprHold(target); if (espLoadModule(route, conn->dispatcher, "view", mprJoinPath(route->documents, target), &errMsg) < 0) { mprRelease(target); return 0; } mprRelease(target); } #endif if ((viewProc = mprLookupKey(eroute->views, target)) == 0) { return 0; } if (!(flags & ESP_DONT_RENDER)) { if (route->flags & HTTP_ROUTE_XSRF) { /* Add a new unique security token */ httpAddSecurityToken(conn, 1); } httpSetContentType(conn, "text/html"); httpSetFilename(conn, mprJoinPath(route->documents, target), 0); /* WARNING: may GC yield */ (viewProc)(conn); } return 1; }