int bridge_request()

in modules/fcgid/fcgid_bridge.c [738:794]


int bridge_request(request_rec * r, int role, fcgid_cmd_conf *cmd_conf)
{
    apr_bucket_brigade *output_brigade, *body_brigade;
    apr_bucket *bucket_eos;
    char **envp;
    int rc;

    /* Create brigade for the request to fastcgi server */
    body_brigade
        = apr_brigade_create(r->pool, r->connection->bucket_alloc);
    output_brigade =
        apr_brigade_create(r->pool, r->connection->bucket_alloc);

    /* In responder mode, handle the request body up front to ensure
     * the content-length is known (even if the request body is
     * chunked) and sent in the header. */
    if (role == FCGI_RESPONDER) {
        apr_off_t body_length;
        
        rc = add_request_body(r, r->pool, body_brigade, &body_length);
        if (rc) {
            return rc;
        }

        if (body_length && !apr_table_get(r->headers_in, "Content-Length")) {
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                          "mod_fcgid: dechunked request body length %" APR_OFF_T_FMT,
                          body_length);
        
            apr_table_set(r->subprocess_env, "CONTENT_LENGTH",
                          apr_off_t_toa(r->pool, body_length));
            apr_table_unset(r->subprocess_env, "HTTP_TRANSFER_ENCODING");
        }
    }

    envp = ap_create_environment(r->pool, r->subprocess_env);
          
    /* Build the begin request and environ request, add them to output_brigade */
    if (!build_begin_block
        (role, r, r->connection->bucket_alloc, output_brigade)
        || !build_env_block(r, envp, r->connection->bucket_alloc,
                            output_brigade)) {
        ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
                      "mod_fcgid: can't build begin or env request");
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    /* Append the body output. */
    APR_BRIGADE_CONCAT(output_brigade, body_brigade);

    /* The eos bucket now */
    bucket_eos = apr_bucket_eos_create(r->connection->bucket_alloc);
    APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_eos);

    /* Bridge the request */
    return handle_request(r, role, cmd_conf, output_brigade);
}