コード例 #1
0
ファイル: pipeline.c プロジェクト: jsjohnst/appweb
//  TODO - should be MapUrl
char *maMapUriToStorage(MaConn *conn, cchar *url)
{
    MaAlias     *alias;

    alias = maGetAlias(conn->request->host, url);
    if (alias == 0) {
        return 0;
    }
    return makeFilename(conn, alias, url, 1);
}
コード例 #2
0
ファイル: request.c プロジェクト: gamman/appweb-3
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;
}
コード例 #3
0
ファイル: pipeline.c プロジェクト: jsjohnst/appweb
/*
 *  Find the matching handler for a request. If any errors occur, the pass handler is used to pass errors onto the 
 *  net/sendfile connectors to send to the client. This routine may rewrite the request URI and may redirect the request.
 */
void maMatchHandler(MaConn *conn)
{
    MaRequest       *req;
    MaResponse      *resp;
    MaHost          *host;
    MaAlias         *alias;
    MaStage         *handler;
    bool            rescan;
    int             loopCount;

    req = conn->request;
    resp = conn->response;
    host = req->host;

    /*
     *  Find the alias that applies for this url. There is always a catch-all alias for the document root.
     */
    alias = req->alias = maGetAlias(host, req->url);
    mprAssert(alias);
    if (alias->redirectCode) {
        // TODO - what about internal redirects?
        maRedirect(conn, alias->redirectCode, alias->uri);
        return;
    }

    if (conn->requestFailed || conn->request->method & (MA_REQ_OPTIONS | MA_REQ_TRACE)) {
        handler = conn->http->passHandler;
        return;
    }

    /*
     *  Get the best (innermost) location block and see if a handler is explicitly set for that location block.
     *  Possibly rewrite the url and retry.
     */
    loopCount = MA_MAX_REWRITE;
    do {
        rescan = 0;
        if ((handler = findLocationHandler(conn)) == 0) {
            /*
             *  Didn't find a location block handler, so try to match by extension and by handler match() routines.
             *  This may invoke processDirectory which may redirect and thus require reprocessing -- hence the loop.
             */
            handler = findHandlerByExtension(conn);
        }

        if (handler && !(handler->flags & MA_STAGE_VIRTUAL)) {
            if (!mapToFile(conn, &rescan)) {
                return;
            }
        }
    } while (handler && rescan && loopCount-- > 0);

    if (handler == 0) {
        maFailRequest(conn, MPR_HTTP_CODE_BAD_METHOD, "Requested method %s not supported for URL: %s", 
            req->methodName, req->url);
        handler = conn->http->passHandler;
    }
    resp->handler = handler;

    mprLog(resp, 4, "Select handler: \"%s\" for \"%s\"", handler->name, req->url);

    setEnv(conn);
}