如何在请求处理程序中从apache bucket brigade读取数据而不使用它?

时间:2018-06-04 06:17:25

标签: c apache2 apache2.4 apache2-module

在apache模块中,如果处理程序拒绝请求,请求将传递给下一个合适的处理程序。我发现如果我读取了bucket_brigade / request body,然后拒绝了请求,则下一个处理程序不会获取任何数据。这就像阅读斗旅消耗它的行为一样。

我想让一个请求处理程序读取数据,执行一些任务(在这种情况下只计算字节数),并拒绝请求而不消耗下一个处理程序的数据。

int my_declining_handler(request_rec *r) {
    apr_status_t status;
    int end = 0;
    apr_size_t bytes, count = 0;
    const char *buf;
    apr_bucket *b;
    apr_bucket_brigade *temp_brigade;

    // here: header check for content-length/transfer encoding

    temp_brigade = apr_brigade_create(r->pool, r->connection->bucket_alloc);
    do {
        status = ap_get_brigade(r->input_filters, temp_brigade, AP_MODE_READBYTES, APR_BLOCK_READ, BUFLEN);
        if (status == APR_SUCCESS) {/* Loop over the contents of temp_brigade */
            for (b = APR_BRIGADE_FIRST(temp_brigade);
                 b != APR_BRIGADE_SENTINEL(temp_brigade);
                 b = APR_BUCKET_NEXT(b)) {
                if (APR_BUCKET_IS_EOS(b)) {
                    end = 1;
                    break;
                }
                else if (APR_BUCKET_IS_METADATA(b)) {
                    continue;
                }
                bytes = BUFLEN;
                status = apr_bucket_read(b, &buf, &bytes,
                                         APR_BLOCK_READ);
                count += bytes;

                apr_bucket_delete(b);
            }
        }
        apr_brigade_cleanup(temp_brigade);
    } while (!end && (status == APR_SUCCESS));
    if (status == APR_SUCCESS) {
        return DECLINED;
    } else {
        return HTTP_INTERNAL_SERVER_ERROR;
    }
}

0 个答案:

没有答案