Blame test/serf_request.c

Packit 3adb1e
/* ====================================================================
Packit 3adb1e
 *    Licensed to the Apache Software Foundation (ASF) under one
Packit 3adb1e
 *    or more contributor license agreements.  See the NOTICE file
Packit 3adb1e
 *    distributed with this work for additional information
Packit 3adb1e
 *    regarding copyright ownership.  The ASF licenses this file
Packit 3adb1e
 *    to you under the Apache License, Version 2.0 (the
Packit 3adb1e
 *    "License"); you may not use this file except in compliance
Packit 3adb1e
 *    with the License.  You may obtain a copy of the License at
Packit 3adb1e
 *
Packit 3adb1e
 *      http://www.apache.org/licenses/LICENSE-2.0
Packit 3adb1e
 *
Packit 3adb1e
 *    Unless required by applicable law or agreed to in writing,
Packit 3adb1e
 *    software distributed under the License is distributed on an
Packit 3adb1e
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Packit 3adb1e
 *    KIND, either express or implied.  See the License for the
Packit 3adb1e
 *    specific language governing permissions and limitations
Packit 3adb1e
 *    under the License.
Packit 3adb1e
 * ====================================================================
Packit 3adb1e
 */
Packit 3adb1e
Packit 3adb1e
#include <stdlib.h>
Packit 3adb1e
Packit 3adb1e
#include "serf.h"
Packit 3adb1e
Packit 3adb1e
static apr_status_t drain_bucket(serf_bucket_t *bucket)
Packit 3adb1e
{
Packit 3adb1e
    apr_status_t status;
Packit 3adb1e
    const char *data;
Packit 3adb1e
    apr_size_t len;
Packit 3adb1e
Packit 3adb1e
    while (1) {
Packit 3adb1e
        status = serf_bucket_read(bucket, 2048, &data, &len;;
Packit 3adb1e
        if (SERF_BUCKET_READ_ERROR(status))
Packit 3adb1e
            return status;
Packit 3adb1e
Packit 3adb1e
        /* got some data. print it out. */
Packit 3adb1e
        fwrite(data, 1, len, stdout);
Packit 3adb1e
Packit 3adb1e
        /* are we done yet? */
Packit 3adb1e
        if (APR_STATUS_IS_EOF(status)) {
Packit 3adb1e
            return APR_EOF;
Packit 3adb1e
        }
Packit 3adb1e
Packit 3adb1e
        /* have we drained the response so far? */
Packit 3adb1e
        if (APR_STATUS_IS_EAGAIN(status))
Packit 3adb1e
            return APR_SUCCESS;
Packit 3adb1e
Packit 3adb1e
        /* loop to read some more. */
Packit 3adb1e
    }
Packit 3adb1e
    /* NOTREACHED */
Packit 3adb1e
}
Packit 3adb1e
Packit 3adb1e
int main(int argc, const char **argv)
Packit 3adb1e
{
Packit 3adb1e
    apr_pool_t *pool;
Packit 3adb1e
    serf_bucket_t *req_bkt;
Packit 3adb1e
    serf_bucket_t *hdrs_bkt;
Packit 3adb1e
    serf_bucket_alloc_t *allocator;
Packit 3adb1e
Packit 3adb1e
    apr_initialize();
Packit 3adb1e
    atexit(apr_terminate);
Packit 3adb1e
Packit 3adb1e
    apr_pool_create(&pool, NULL);
Packit 3adb1e
    /* serf_initialize(); */
Packit 3adb1e
Packit 3adb1e
    allocator = serf_bucket_allocator_create(pool, NULL, NULL);
Packit 3adb1e
Packit 3adb1e
    req_bkt = serf_bucket_request_create("GET", "/", NULL, allocator);
Packit 3adb1e
Packit 3adb1e
    hdrs_bkt = serf_bucket_request_get_headers(req_bkt);
Packit 3adb1e
Packit 3adb1e
    /* FIXME: Shouldn't we be able to figure out the host ourselves? */
Packit 3adb1e
    serf_bucket_headers_setn(hdrs_bkt, "Host", "localhost");
Packit 3adb1e
    serf_bucket_headers_setn(hdrs_bkt, "User-Agent",
Packit 3adb1e
                             "Serf/" SERF_VERSION_STRING);
Packit 3adb1e
Packit 3adb1e
    (void) drain_bucket(req_bkt);
Packit 3adb1e
Packit 3adb1e
    serf_bucket_destroy(req_bkt);
Packit 3adb1e
Packit 3adb1e
    apr_pool_destroy(pool);
Packit 3adb1e
Packit 3adb1e
    return 0;
Packit 3adb1e
}