Exemple #1
0
static void startProxy(HttpQueue *q)
{
#if UNUSED
    HttpConn    *conn, *target;
    MprHash     *hp;

    conn = q->conn;
    rx = conn->rx;
    loc = rx->loc;
    
    httpo
    uri = httpJoinUriPath(NULL, rx->parsedUri, loc->prefix);

    pp->target = getConnection(conn);

    - how to hook into the pipeline for the target

    if (httpConnect(pp->target, rx->method, httpUriToString(uri)) < 0) {
        for (mprGetFirstHash(rx->headers); hp; hp = mprGetNextHash(rx->headers, hp)) {
            httpSetHeader(target, hp->key, hp->data);
        }
        httpSetHeader(target, "X-Forwarded-Host", );
        httpSetHeader(target, "Host", );
        httpSetHeader(target, "X-Forwarded-Server", );
        httpSetHeader(target, "X-Forwarded-For", );
    }
    //  Push headers out - this may not work
    httpFlush(conn);
#endif
}
Exemple #2
0
PUBLIC HttpUri *httpJoinUri(HttpUri *uri, int argc, HttpUri **others)
{
    HttpUri     *other;
    int         i;

    if ((uri = httpCloneUri(uri, 0)) == 0) {
        return 0;
    }
    if (!uri->valid) {
        return 0;
    }
    for (i = 0; i < argc; i++) {
        other = others[i];
        if (other->scheme) {
            uri->scheme = sclone(other->scheme);
            uri->port = other->port;
        }
        if (other->host) {
            uri->host = sclone(other->host);
            uri->port = other->port;
        }
        if (other->path) {
            httpJoinUriPath(uri, uri, other);
        }
        if (other->reference) {
            uri->reference = sclone(other->reference);
        }
        if (other->query) {
            uri->query = sclone(other->query);
        }
    }
    uri->ext = mprGetPathExt(uri->path);
    return uri;
}
Exemple #3
0
PUBLIC HttpUri *httpResolveUri(HttpConn *conn, HttpUri *base, HttpUri *other)
{
    HttpHost        *host;
    HttpEndpoint    *endpoint;
    HttpUri         *current;

    if (!base || !base->valid) {
        return other;
    }
    if (!other || !other->valid) {
        return base;
    }
    current = httpCloneUri(base, 0);

    /*
        Must not inherit the query or reference
     */
    current->query = 0;
    current->reference = 0;

    if (other->scheme && !smatch(current->scheme, other->scheme)) {
        current->scheme = sclone(other->scheme);
        /*
            If the scheme is changed (test above), then accept an explict port.
            If no port, then must not use the current port as the scheme has changed.
         */
        if (other->port) {
            current->port = other->port;
        } else {
            host = conn ? conn->host : httpGetDefaultHost();
            endpoint = smatch(current->scheme, "https") ? host->secureEndpoint : host->defaultEndpoint;
            if (endpoint) {
                current->port = endpoint->port;
            } else {
                current->port = 0;
            }
        }
    }
    if (other->host) {
        current->host = sclone(other->host);
    }
    if (other->port) {
        current->port = other->port;
    }
    if (other->path) {
        trimPathToDirname(current);
        httpJoinUriPath(current, current, other);
        current->path = httpNormalizeUriPath(current->path);
    }
    if (other->reference) {
        current->reference = sclone(other->reference);
    }
    if (other->query) {
        current->query = sclone(other->query);
    }
    current->ext = mprGetPathExt(current->path);
    return current;
}
Exemple #4
0
PUBLIC HttpUri *httpResolveUri(HttpUri *base, int argc, HttpUri **others, bool local)
{
    HttpUri     *current, *other;
    int         i;

    if ((current = httpCloneUri(base, 0)) == 0) {
        return 0;
    }
    if (local) {
        current->host = 0;
        current->scheme = 0;
        current->port = 0;
    }
    /*
        Must not inherit the query or reference
     */
    current->query = 0;
    current->reference = 0;

    for (i = 0; i < argc; i++) {
        other = others[i];
        if (other->scheme && !smatch(current->scheme, other->scheme)) {
            current->scheme = sclone(other->scheme);
            /*
                If the scheme is changed (test above), then accept an explict port.
                If no port, then must not use the current port as the scheme has changed.
             */
            if (other->port) {
                current->port = other->port;
            } else if (current->port) {
                current->port = 0;
            }
        }
        if (other->host) {
            current->host = sclone(other->host);
        }
        if (other->port) {
            current->port = other->port;
        }
        if (other->path) {
            trimPathToDirname(current);
            httpJoinUriPath(current, current, other);
        }
        if (other->reference) {
            current->reference = sclone(other->reference);
        }
        if (other->query) {
            current->query = sclone(other->query);
        }
    }
    current->ext = mprGetPathExt(current->path);
    return current;
}
Exemple #5
0
/*  
    Make an absolute reference for "this" URI.

    function absolute(base): Uri
 */
static EjsUri *uri_absolute(Ejs *ejs, EjsUri *up, int argc, EjsObj **argv)
{
    EjsUri      *result;
    HttpUri     *uri, *baseUri;

    if (argc >= 1) {
        baseUri = toHttpUri(ejs, argv[0], 0);
        result = cloneUri(ejs, up, 0);
        uri = result->uri;
        if (uri->path && uri->path[0] != '/') {
            httpJoinUriPath(uri, baseUri, uri);
        }
        httpCompleteUri(result->uri, baseUri);
    } else {
        result = cloneUri(ejs, up, 0);
        httpCompleteUri(result->uri, NULL);
    }
    httpNormalizeUri(result->uri);
    return result;
}