int maSetRequestUri(MaConn *conn, cchar *uri, cchar *query) { MaRequest *req; MaResponse *resp; MaHost *host; MprUri *prior; char *cp; if (uri == 0 || *uri == 0) { uri = "/"; } host = conn->host; req = conn->request; resp = conn->response; prior = req->parsedUri; if ((req->parsedUri = mprParseUri(req, uri)) == 0) { return MPR_ERR_BAD_ARGS; } if (prior) { if ((cp = strstr(uri, "://")) == 0) { req->parsedUri->scheme = prior->scheme; req->parsedUri->host = prior->host; } else if (strchr(&cp[3], ':') == 0) { req->parsedUri->port = prior->port; } } if (query == 0 && prior) { req->parsedUri->query = prior->query; } else if (*query) { req->parsedUri->query = mprStrdup(req->parsedUri, query); } req->url = mprValidateUrl(req, mprUrlDecode(req, req->parsedUri->url)); req->alias = maGetAlias(host, req->url); resp->filename = maMakeFilename(conn, req->alias, req->url, 1); if ((req->dir = maLookupBestDir(req->host, resp->filename)) != 0) { if (req->dir->auth) { req->auth = req->dir->auth; } } req->location = maLookupBestLocation(host, req->url); if (req->auth == 0) { req->auth = req->location->auth; } mprGetPathInfo(conn, resp->filename, &resp->fileInfo); resp->extension = maGetExtension(conn); if ((resp->mimeType = (char*) maLookupMimeType(host, resp->extension)) == 0) { resp->mimeType = (char*) "text/html"; } return 0; }
static MaStage *findLocationHandler(MaConn *conn) { MaRequest *req; MaResponse *resp; MaLocation *location; int loopCount; req = conn->request; resp = conn->response; loopCount = MA_MAX_REWRITE; do { location = req->location = maLookupBestLocation(req->host, req->url); mprAssert(location); req->auth = location->auth; resp->handler = checkStage(conn, location->handler); } while (maRewriteUri(conn) && --loopCount > 0); return resp->handler; }