Пример #1
0
static int processThread(HttpConn *conn, MprEvent *event)
{
    ThreadData  *td;
    cchar       *path;
    char        *url;
    int         next;

    td = mprGetCurrentThread()->data;
    httpFollowRedirects(conn, !app->nofollow);
    httpSetTimeout(conn, app->timeout, app->timeout);

    if (strcmp(app->protocol, "HTTP/1.0") == 0) {
        httpSetKeepAliveCount(conn, 0);
        httpSetProtocol(conn, "HTTP/1.0");
    }
    if (app->username) {
        if (app->password == 0 && !strchr(app->username, ':')) {
            app->password = getPassword();
        }
        httpSetCredentials(conn, app->username, app->password);
    }
    while (!mprShouldDenyNewRequests(conn) && (app->success || app->continueOnErrors)) {
        if (app->singleStep) waitForUser();
        if (app->files && !app->upload) {
            for (next = 0; (path = mprGetNextItem(app->files, &next)) != 0; ) {
                /*
                    If URL ends with "/", assume it is a directory on the target and append each file name 
                 */
                if (app->target[strlen(app->target) - 1] == '/') {
                    url = mprJoinPath(app->target, mprGetPathBase(path));
                } else {
                    url = app->target;
                }
                app->requestFiles = mprCreateList(-1, MPR_LIST_STATIC_VALUES);
                mprAddItem(app->requestFiles, path);
                td->url = url = resolveUrl(conn, url);
                if (app->verbose) {
                    mprPrintf("putting: %s to %s\n", path, url);
                }
                if (doRequest(conn, url, app->requestFiles) < 0) {
                    app->success = 0;
                    break;
                }
            }
        } else {
            td->url = url = resolveUrl(conn, app->target);
            if (doRequest(conn, url, app->files) < 0) {
                app->success = 0;
                break;
            }
        }
        if (iterationsComplete()) {
            break;
        }
    }
    httpDestroyConn(conn);
    finishThread((MprThread*) event->data);
    return -1;
}
Пример #2
0
static void processThread(MprCtx ctx)
{
    MprHttp     *http;
    MprList     *files;
    cchar       *path;
    char        *url;
    int         next;

    http = mprCreateHttp(ctx);
    mprSetHttpTimeout(http, timeout);
    mprSetHttpFollowRedirects(http, !nofollow);

    if (chunkSize) {
        mprSetHttpChunked(http, 1);
    }
    if (httpVersion == 0) {
        mprSetHttpKeepAlive(http, 0);
        mprSetHttpProtocol(http, "HTTP/1.0");
    }
    if (username) {
        if (password == 0 && !strchr(username, ':')) {
            password = getPassword(http);
        }
        mprSetHttpCredentials(http, username, password);
    }
    while (!mprIsExiting(http) && (success || continueOnErrors)) {
        if (singleStep) waitForUser(http);
        if (fileData && !upload) {
            for (next = 0; (path = mprGetNextItem(fileData, &next)) != 0; ) {
                if (target[strlen(target) - 1] == '/') {
                    url = mprJoinPath(http, target, mprGetPathBase(http, path));
                } else {
                    url = target;
                }
                files = mprCreateList(http);
                mprAddItem(files, path);
                url = resolveUrl(http, url);
                if (verbose) {
                    mprPrintf(http, "putting: %s to %s\n", path, url);
                }
                if (doRequest(http, url, formData, files) < 0) {
                    success = 0;
                    mprFree(files);
                    mprFree(url);
                    break;
                }
                mprFree(files);
                mprFree(url);
            }
        } else {
            url = resolveUrl(http, target);
            if (doRequest(http, url, formData, fileData) < 0) {
                success = 0;
                mprFree(url);
                break;
            }
        }
        if (iterationsComplete(http)) 
            break;
    }
    mprFree(http);
}