/* Open handler for a new request */ static void openPhp(HttpQueue *q) { HttpRx *rx; rx = q->conn->rx; /* PHP will buffer all input. i.e. does not stream. The normal Limits still apply. */ q->max = q->pair->max = MAXINT; mprLog(5, "Open php handler"); httpTrimExtraPath(q->conn); if (rx->flags & (HTTP_OPTIONS | HTTP_TRACE)) { httpHandleOptionsTrace(q->conn, "DELETE,GET,HEAD,POST,PUT"); } else if (rx->flags & (HTTP_GET | HTTP_HEAD | HTTP_POST | HTTP_PUT)) { httpMapFile(q->conn, rx->route); if (!q->stage->stageData) { if (initializePhp(q->conn->http) < 0) { httpError(q->conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "PHP initialization failed"); } q->stage->stageData = mprAlloc(1); } q->queueData = mprAllocObj(MaPhp, NULL); } else { httpError(q->conn, HTTP_CODE_BAD_METHOD, "Method not supported by file handler: %s", rx->method); } }
static void startPass(HttpQueue *q) { mprLog(5, "Start passHandler"); if (q->conn->rx->flags & (HTTP_OPTIONS | HTTP_TRACE)) { httpHandleOptionsTrace(q->conn); } }
/* Open an instance of the ESP for a new request */ static void openEsp(HttpQueue *q) { HttpConn *conn; HttpRx *rx; HttpRoute *route; EspRoute *eroute; EspReq *req; conn = q->conn; rx = conn->rx; if (rx->flags & (HTTP_OPTIONS | HTTP_TRACE)) { httpHandleOptionsTrace(q->conn); } else { if ((req = mprAllocObj(EspReq, manageReq)) == 0) { httpMemoryError(conn); return; } /* Find the ESP route configuration. Search up the route parent chain */ for (eroute = 0, route = rx->route; route; route = route->parent) { if (route->eroute) { eroute = route->eroute; break; } } if (!eroute) { // MOB - should be saved for future similar requests (locking too) eroute = allocEspRoute(route); return; } conn->data = req; req->esp = esp; req->route = route; req->eroute = eroute; req->autoFinalize = 1; } /* If unloading a module, this lock will cause a wait here while ESP applications are reloaded */ lock(esp); esp->inUse++; unlock(esp); }
static void openFileHandler(HttpQueue *q) { HttpRx *rx; HttpTx *tx; HttpRoute *route; HttpConn *conn; MprPath *info; char *date; conn = q->conn; tx = conn->tx; rx = conn->rx; route = rx->route; info = &tx->fileInfo; if (rx->flags & (HTTP_PUT | HTTP_DELETE)) { if (!(route->flags & HTTP_ROUTE_PUT_DELETE_METHODS)) { httpError(q->conn, HTTP_CODE_BAD_METHOD, "The \"%s\" method is not supported by file handler", rx->method); } } else { if (rx->flags & (HTTP_GET | HTTP_HEAD | HTTP_POST)) { if (!(info->valid || info->isDir)) { if (rx->referrer) { mprLog(2, "fileHandler: Cannot find filename %s from referrer %s", tx->filename, rx->referrer); } else { mprLog(2, "fileHandler: Cannot find filename %s", tx->filename); } httpError(conn, HTTP_CODE_NOT_FOUND, "Cannot find %s", rx->uri); } else if (info->valid) { if (!tx->etag) { /* Set the etag for caching in the client */ tx->etag = sfmt("\"%Lx-%Lx-%Lx\"", (int64) info->inode, (int64) info->size, (int64) info->mtime); } } } if (rx->flags & (HTTP_GET | HTTP_HEAD | HTTP_POST) && !conn->error) { if (tx->fileInfo.valid && tx->fileInfo.mtime) { // TODO - OPT could cache this date = httpGetDateString(&tx->fileInfo); httpSetHeader(conn, "Last-Modified", date); } if (httpContentNotModified(conn)) { httpSetStatus(conn, HTTP_CODE_NOT_MODIFIED); httpOmitBody(conn); tx->length = -1; } if (!tx->fileInfo.isReg && !tx->fileInfo.isLink) { httpError(conn, HTTP_CODE_NOT_FOUND, "Cannot locate document: %s", rx->uri); } else if (tx->fileInfo.size > conn->limits->transmissionBodySize) { httpError(conn, HTTP_ABORT | HTTP_CODE_REQUEST_TOO_LARGE, "Http transmission aborted. File size exceeds max body of %,Ld bytes", conn->limits->transmissionBodySize); } else if (!(tx->connector == conn->http->sendConnector)) { /* If using the net connector, open the file if a body must be sent with the response. The file will be automatically closed when the request completes. */ if (!(tx->flags & HTTP_TX_NO_BODY)) { tx->file = mprOpenFile(tx->filename, O_RDONLY | O_BINARY, 0); if (tx->file == 0) { if (rx->referrer) { httpError(conn, HTTP_CODE_NOT_FOUND, "Cannot open document: %s from %s", tx->filename, rx->referrer); } else { httpError(conn, HTTP_CODE_NOT_FOUND, "Cannot open document: %s from %s", tx->filename); } } } } } else if (rx->flags & (HTTP_OPTIONS | HTTP_TRACE)) { if (route->flags & HTTP_ROUTE_PUT_DELETE_METHODS) { httpHandleOptionsTrace(q->conn, "DELETE,GET,HEAD,POST,PUT"); } else { httpHandleOptionsTrace(q->conn, "GET,HEAD,POST"); } } } }