--- mod_dav.c.old Mon Aug 4 21:35:02 2003 +++ mod_dav.c.old Mon Aug 4 23:16:48 2003 @@ -982,41 +982,49 @@ } if (err == NULL) { - if (ap_should_client_block(r)) { - char *buffer = apr_palloc(r->pool, DAV_READ_BLOCKSIZE); - long len; + apr_status_t rv; + apr_bucket_brigade *bb; + apr_bucket *b; + const char *buf; + apr_ssize_t len; + bb = apr_brigade_create(r->pool, r->connection->bucket_alloc); + if (bb == NULL) { + err = dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + "Could not create brigade."); + goto done; + } + for (;;) { + rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES, + APR_BLOCK_READ, DAV_READ_BLOCKSIZE); + if (rv != APR_SUCCESS) { + err = dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + "Could not get brigade."); + goto done; + } /* * Once we start reading the request, then we must read the * whole darn thing. ap_discard_request_body() won't do anything * for a partially-read request. */ - - while ((len = ap_get_client_block(r, buffer, - DAV_READ_BLOCKSIZE)) > 0) { - if (err == NULL) { - /* write whatever we read, until we see an error */ - err = (*resource->hooks->write_stream)(stream, - buffer, len); - } - } - - /* - * ### what happens if we read more/less than the amount - * ### specified in the Content-Range? eek... - */ - - if (len == -1) { - /* - * Error reading request body. This has precedence over - * prior errors. - */ - err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, - "An error occurred while reading the " - "request body."); - } + APR_BRIGADE_FOREACH(b, bb) { + if (APR_BUCKET_IS_EOS(b)) + goto done; + if ((rv = apr_bucket_read(b, (const char **)&buf, &len, + APR_BLOCK_READ)) != APR_SUCCESS && + err == NULL) + err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, + "An error occurred while reading the " + "request body."); + if (err == NULL) + /* write whatever we read, until we see an error */ + err = (*resource->hooks->write_stream)(stream, + buf, len); + } } - +done: + if (bb != NULL) + apr_brigade_destroy(bb); err2 = (*resource->hooks->close_stream)(stream, err == NULL /* commit */); if (err2 != NULL && err == NULL) {