1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file core_filters.c
19 * @brief Core input/output network filters.
23 #include "apr_strings.h"
25 #include "apr_fnmatch.h"
27 #include "apr_thread_proc.h" /* for RLIMIT stuff */
28 #include "apr_hooks.h"
30 #define APR_WANT_IOVEC
31 #define APR_WANT_STRFUNC
32 #define APR_WANT_MEMFUNC
35 #include "ap_config.h"
37 #include "http_config.h"
38 #include "http_core.h"
39 #include "http_protocol.h" /* For index_of_response(). Grump. */
40 #include "http_request.h"
41 #include "http_vhost.h"
42 #include "http_main.h" /* For the default_handler below... */
45 #include "http_connection.h"
46 #include "apr_buckets.h"
47 #include "util_filter.h"
48 #include "util_ebcdic.h"
49 #include "mpm_common.h"
50 #include "scoreboard.h"
52 #include "mod_proxy.h"
53 #include "ap_listen.h"
55 #include "mod_so.h" /* for ap_find_loaded_module_symbol */
57 #define AP_MIN_SENDFILE_BYTES (256)
60 * Remove all zero length buckets from the brigade.
62 #define BRIGADE_NORMALIZE(b) \
64 apr_bucket *e = APR_BRIGADE_FIRST(b); \
66 if (e->length == 0 && !APR_BUCKET_IS_METADATA(e)) { \
68 d = APR_BUCKET_NEXT(e); \
69 apr_bucket_delete(e); \
73 e = APR_BUCKET_NEXT(e); \
75 } while (!APR_BRIGADE_EMPTY(b) && (e != APR_BRIGADE_SENTINEL(b))); \
78 APLOG_USE_MODULE(core);
80 int ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
81 ap_input_mode_t mode, apr_read_type_e block,
86 core_net_rec *net = f->ctx;
87 core_ctx_t *ctx = net->in_ctx;
91 if (mode == AP_MODE_INIT) {
93 * this mode is for filters that might need to 'initialize'
94 * a connection before reading request data from a client.
95 * NNTP over SSL for example needs to handshake before the
96 * server sends the welcome message.
97 * such filters would have changed the mode before this point
98 * is reached. however, protocol modules such as NNTP should
99 * not need to know anything about SSL. given the example, if
100 * SSL is not in the filter chain, AP_MODE_INIT is a noop.
107 ctx = apr_pcalloc(f->c->pool, sizeof(*ctx));
108 ctx->b = apr_brigade_create(f->c->pool, f->c->bucket_alloc);
109 ctx->tmpbb = apr_brigade_create(ctx->b->p, ctx->b->bucket_alloc);
110 /* seed the brigade with the client socket. */
111 e = apr_bucket_socket_create(net->client_socket, f->c->bucket_alloc);
112 APR_BRIGADE_INSERT_TAIL(ctx->b, e);
115 else if (APR_BRIGADE_EMPTY(ctx->b)) {
119 /* ### This is bad. */
120 BRIGADE_NORMALIZE(ctx->b);
122 /* check for empty brigade again *AFTER* BRIGADE_NORMALIZE()
123 * If we have lost our socket bucket (see above), we are EOF.
125 * Ideally, this should be returning SUCCESS with EOS bucket, but
126 * some higher-up APIs (spec. read_request_line via ap_rgetline)
127 * want an error code. */
128 if (APR_BRIGADE_EMPTY(ctx->b)) {
132 if (mode == AP_MODE_GETLINE) {
133 /* we are reading a single LF line, e.g. the HTTP headers */
134 rv = apr_brigade_split_line(b, ctx->b, block, HUGE_STRING_LEN);
135 /* We should treat EAGAIN here the same as we do for EOF (brigade is
136 * empty). We do this by returning whatever we have read. This may
137 * or may not be bogus, but is consistent (for now) with EOF logic.
139 if (APR_STATUS_IS_EAGAIN(rv)) {
145 /* ### AP_MODE_PEEK is a horrific name for this mode because we also
146 * eat any CRLFs that we see. That's not the obvious intention of
147 * this mode. Determine whether anyone actually uses this or not. */
148 if (mode == AP_MODE_EATCRLF) {
152 /* The purpose of this loop is to ignore any CRLF (or LF) at the end
153 * of a request. Many browsers send extra lines at the end of POST
154 * requests. We use the PEEK method to determine if there is more
155 * data on the socket, so that we know if we should delay sending the
156 * end of one request until we have served the second request in a
157 * pipelined situation. We don't want to actually delay sending a
158 * response if the server finds a CRLF (or LF), becuause that doesn't
159 * mean that there is another request, just a blank line.
162 if (APR_BRIGADE_EMPTY(ctx->b))
165 e = APR_BRIGADE_FIRST(ctx->b);
167 rv = apr_bucket_read(e, &str, &len, APR_NONBLOCK_READ);
169 if (rv != APR_SUCCESS)
173 while (c < str + len) {
174 if (*c == APR_ASCII_LF)
176 else if (*c == APR_ASCII_CR && *(c + 1) == APR_ASCII_LF)
182 /* If we reach here, we were a bucket just full of CRLFs, so
183 * just toss the bucket. */
184 /* FIXME: Is this the right thing to do in the core? */
185 apr_bucket_delete(e);
190 /* If mode is EXHAUSTIVE, we want to just read everything until the end
191 * of the brigade, which in this case means the end of the socket.
192 * To do this, we attach the brigade that has currently been setaside to
193 * the brigade that was passed down, and send that brigade back.
195 * NOTE: This is VERY dangerous to use, and should only be done with
196 * extreme caution. FWLIW, this would be needed by an MPM like Perchild;
197 * such an MPM can easily request the socket and all data that has been
198 * read, which means that it can pass it to the correct child process.
200 if (mode == AP_MODE_EXHAUSTIVE) {
203 /* Tack on any buckets that were set aside. */
204 APR_BRIGADE_CONCAT(b, ctx->b);
206 /* Since we've just added all potential buckets (which will most
207 * likely simply be the socket bucket) we know this is the end,
208 * so tack on an EOS too. */
209 /* We have read until the brigade was empty, so we know that we
211 e = apr_bucket_eos_create(f->c->bucket_alloc);
212 APR_BRIGADE_INSERT_TAIL(b, e);
216 /* read up to the amount they specified. */
217 if (mode == AP_MODE_READBYTES || mode == AP_MODE_SPECULATIVE) {
220 AP_DEBUG_ASSERT(readbytes > 0);
222 e = APR_BRIGADE_FIRST(ctx->b);
223 rv = apr_bucket_read(e, &str, &len, block);
225 if (APR_STATUS_IS_EAGAIN(rv)) {
228 else if (rv != APR_SUCCESS) {
231 else if (block == APR_BLOCK_READ && len == 0) {
232 /* We wanted to read some bytes in blocking mode. We read
233 * 0 bytes. Hence, we now assume we are EOS.
235 * When we are in normal mode, return an EOS bucket to the
237 * When we are in speculative mode, leave ctx->b empty, so
238 * that the next call returns an EOS bucket.
240 apr_bucket_delete(e);
242 if (mode == AP_MODE_READBYTES) {
243 e = apr_bucket_eos_create(f->c->bucket_alloc);
244 APR_BRIGADE_INSERT_TAIL(b, e);
249 /* Have we read as much data as we wanted (be greedy)? */
250 if (len < readbytes) {
251 apr_size_t bucket_len;
254 /* We already registered the data in e in len */
255 e = APR_BUCKET_NEXT(e);
256 while ((len < readbytes) && (rv == APR_SUCCESS)
257 && (e != APR_BRIGADE_SENTINEL(ctx->b))) {
258 /* Check for the availability of buckets with known length */
259 if (e->length != -1) {
261 e = APR_BUCKET_NEXT(e);
265 * Read from bucket, but non blocking. If there isn't any
266 * more data, well than this is fine as well, we will
267 * not wait for more since we already got some and we are
268 * only checking if there isn't more.
270 rv = apr_bucket_read(e, &str, &bucket_len,
272 if (rv == APR_SUCCESS) {
274 e = APR_BUCKET_NEXT(e);
280 /* We can only return at most what we read. */
281 if (len < readbytes) {
285 rv = apr_brigade_partition(ctx->b, readbytes, &e);
286 if (rv != APR_SUCCESS) {
290 /* Must do move before CONCAT */
291 ctx->tmpbb = apr_brigade_split_ex(ctx->b, e, ctx->tmpbb);
293 if (mode == AP_MODE_READBYTES) {
294 APR_BRIGADE_CONCAT(b, ctx->b);
296 else if (mode == AP_MODE_SPECULATIVE) {
297 apr_bucket *copy_bucket;
299 for (e = APR_BRIGADE_FIRST(ctx->b);
300 e != APR_BRIGADE_SENTINEL(ctx->b);
301 e = APR_BUCKET_NEXT(e))
303 rv = apr_bucket_copy(e, ©_bucket);
304 if (rv != APR_SUCCESS) {
307 APR_BRIGADE_INSERT_TAIL(b, copy_bucket);
311 /* Take what was originally there and place it back on ctx->b */
312 APR_BRIGADE_CONCAT(ctx->b, ctx->tmpbb);
317 static void setaside_remaining_output(ap_filter_t *f,
318 core_output_filter_ctx_t *ctx,
319 apr_bucket_brigade *bb,
322 static apr_status_t send_brigade_nonblocking(apr_socket_t *s,
323 apr_bucket_brigade *bb,
324 apr_size_t *bytes_written,
327 static void remove_empty_buckets(apr_bucket_brigade *bb);
329 static apr_status_t send_brigade_blocking(apr_socket_t *s,
330 apr_bucket_brigade *bb,
331 apr_size_t *bytes_written,
334 static apr_status_t writev_nonblocking(apr_socket_t *s,
335 struct iovec *vec, apr_size_t nvec,
336 apr_bucket_brigade *bb,
337 apr_size_t *cumulative_bytes_written,
341 static apr_status_t sendfile_nonblocking(apr_socket_t *s,
343 apr_size_t *cumulative_bytes_written,
347 #define THRESHOLD_MIN_WRITE 4096
348 #define THRESHOLD_MAX_BUFFER 65536
350 /* Optional function coming from mod_logio, used for logging of output
353 extern APR_OPTIONAL_FN_TYPE(ap_logio_add_bytes_out) *ap__logio_add_bytes_out;
355 apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *new_bb)
358 core_net_rec *net = f->ctx;
359 core_output_filter_ctx_t *ctx = net->out_ctx;
360 apr_bucket_brigade *bb = NULL;
361 apr_bucket *bucket, *next;
362 apr_size_t bytes_in_brigade, non_file_bytes_in_brigade;
365 /* Fail quickly if the connection has already been aborted. */
367 if (new_bb != NULL) {
368 apr_brigade_cleanup(new_bb);
370 return APR_ECONNABORTED;
374 ctx = apr_pcalloc(c->pool, sizeof(*ctx));
375 net->out_ctx = (core_output_filter_ctx_t *)ctx;
376 rv = apr_socket_opt_set(net->client_socket, APR_SO_NONBLOCK, 1);
377 if (rv != APR_SUCCESS) {
381 * Need to create tmp brigade with correct lifetime. Passing
382 * NULL to apr_brigade_split_ex would result in a brigade
383 * allocated from bb->pool which might be wrong.
385 ctx->tmp_flush_bb = apr_brigade_create(c->pool, c->bucket_alloc);
388 if (new_bb != NULL) {
389 for (bucket = APR_BRIGADE_FIRST(new_bb); bucket != APR_BRIGADE_SENTINEL(new_bb); bucket = APR_BUCKET_NEXT(bucket)) {
390 if (bucket->length > 0) {
391 ctx->bytes_in += bucket->length;
397 if ((ctx->buffered_bb != NULL) &&
398 !APR_BRIGADE_EMPTY(ctx->buffered_bb)) {
399 if (new_bb != NULL) {
400 APR_BRIGADE_PREPEND(bb, ctx->buffered_bb);
403 bb = ctx->buffered_bb;
405 c->data_in_output_filters = 0;
407 else if (new_bb == NULL) {
411 /* Scan through the brigade and decide whether to attempt a write,
412 * based on the following rules:
414 * 1) The new_bb is null: Do a nonblocking write of as much as
415 * possible: do a nonblocking write of as much data as possible,
416 * then save the rest in ctx->buffered_bb. (If new_bb == NULL,
417 * it probably means that the MPM is doing asynchronous write
418 * completion and has just determined that this connection
421 * 2) The brigade contains a flush bucket: Do a blocking write
422 * of everything up that point.
424 * 3) The request is in CONN_STATE_HANDLER state, and the brigade
425 * contains at least THRESHOLD_MAX_BUFFER bytes in non-file
426 * buckets: Do blocking writes until the amount of data in the
427 * buffer is less than THRESHOLD_MAX_BUFFER. (The point of this
428 * rule is to provide flow control, in case a handler is
429 * streaming out lots of data faster than the data can be
430 * sent to the client.)
432 * 4) The brigade contains at least THRESHOLD_MIN_WRITE
433 * bytes: Do a nonblocking write of as much data as possible,
434 * then save the rest in ctx->buffered_bb.
437 if (new_bb == NULL) {
438 rv = send_brigade_nonblocking(net->client_socket, bb,
439 &(ctx->bytes_written), c);
440 if (APR_STATUS_IS_EAGAIN(rv)) {
443 else if (rv != APR_SUCCESS) {
444 /* The client has aborted the connection */
447 setaside_remaining_output(f, ctx, bb, c);
451 bytes_in_brigade = 0;
452 non_file_bytes_in_brigade = 0;
453 for (bucket = APR_BRIGADE_FIRST(bb); bucket != APR_BRIGADE_SENTINEL(bb);
455 next = APR_BUCKET_NEXT(bucket);
456 if (APR_BUCKET_IS_FLUSH(bucket)) {
457 ctx->tmp_flush_bb = apr_brigade_split_ex(bb, next, ctx->tmp_flush_bb);
458 rv = send_brigade_blocking(net->client_socket, bb,
459 &(ctx->bytes_written), c);
460 if (rv != APR_SUCCESS) {
461 /* The client has aborted the connection */
465 APR_BRIGADE_CONCAT(bb, ctx->tmp_flush_bb);
466 next = APR_BRIGADE_FIRST(bb);
467 bytes_in_brigade = 0;
468 non_file_bytes_in_brigade = 0;
470 else if (!APR_BUCKET_IS_METADATA(bucket)) {
471 if (bucket->length != (apr_size_t)-1) {
474 /* XXX support nonblocking read here? */
475 rv = apr_bucket_read(bucket, &data, &length, APR_BLOCK_READ);
476 if (rv != APR_SUCCESS) {
479 /* reading may have split the bucket, so recompute next: */
480 next = APR_BUCKET_NEXT(bucket);
482 bytes_in_brigade += bucket->length;
483 if (!APR_BUCKET_IS_FILE(bucket)) {
484 non_file_bytes_in_brigade += bucket->length;
489 if (non_file_bytes_in_brigade >= THRESHOLD_MAX_BUFFER) {
490 /* ### Writing the entire brigade may be excessive; we really just
491 * ### need to send enough data to be under THRESHOLD_MAX_BUFFER.
493 rv = send_brigade_blocking(net->client_socket, bb,
494 &(ctx->bytes_written), c);
495 if (rv != APR_SUCCESS) {
496 /* The client has aborted the connection */
501 else if (bytes_in_brigade >= THRESHOLD_MIN_WRITE) {
502 rv = send_brigade_nonblocking(net->client_socket, bb,
503 &(ctx->bytes_written), c);
504 if ((rv != APR_SUCCESS) && (!APR_STATUS_IS_EAGAIN(rv))) {
505 /* The client has aborted the connection */
511 setaside_remaining_output(f, ctx, bb, c);
515 static void setaside_remaining_output(ap_filter_t *f,
516 core_output_filter_ctx_t *ctx,
517 apr_bucket_brigade *bb,
523 remove_empty_buckets(bb);
524 if (!APR_BRIGADE_EMPTY(bb)) {
525 c->data_in_output_filters = 1;
526 if (bb != ctx->buffered_bb) {
527 /* XXX should this use a separate deferred write pool, like
528 * the original ap_core_output_filter?
530 ap_save_brigade(f, &(ctx->buffered_bb), &bb, c->pool);
531 apr_brigade_cleanup(bb);
536 #ifndef APR_MAX_IOVEC_SIZE
537 #define MAX_IOVEC_TO_WRITE 16
539 #if APR_MAX_IOVEC_SIZE > 16
540 #define MAX_IOVEC_TO_WRITE 16
542 #define MAX_IOVEC_TO_WRITE APR_MAX_IOVEC_SIZE
546 static apr_status_t send_brigade_nonblocking(apr_socket_t *s,
547 apr_bucket_brigade *bb,
548 apr_size_t *bytes_written,
551 apr_bucket *bucket, *next;
553 struct iovec vec[MAX_IOVEC_TO_WRITE];
556 remove_empty_buckets(bb);
558 for (bucket = APR_BRIGADE_FIRST(bb);
559 bucket != APR_BRIGADE_SENTINEL(bb);
561 int did_sendfile = 0;
562 next = APR_BUCKET_NEXT(bucket);
564 if (APR_BUCKET_IS_FILE(bucket)) {
565 apr_bucket_file *file_bucket = (apr_bucket_file *)(bucket->data);
566 apr_file_t *fd = file_bucket->fd;
567 /* Use sendfile to send this file unless:
568 * - the platform doesn't support sendfile,
569 * - the file is too small for sendfile to be useful, or
570 * - sendfile is disabled in the httpd config via "EnableSendfile off"
573 if ((apr_file_flags_get(fd) & APR_SENDFILE_ENABLED) &&
574 (bucket->length >= AP_MIN_SENDFILE_BYTES)) {
577 (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 1);
578 rv = writev_nonblocking(s, vec, nvec, bb, bytes_written, c);
580 if (rv != APR_SUCCESS) {
581 (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 0);
585 rv = sendfile_nonblocking(s, bucket, bytes_written, c);
587 (void)apr_socket_opt_set(s, APR_TCP_NOPUSH, 0);
589 if (rv != APR_SUCCESS) {
595 #endif /* APR_HAS_SENDFILE */
596 if (!did_sendfile && !APR_BUCKET_IS_METADATA(bucket)) {
599 rv = apr_bucket_read(bucket, &data, &length, APR_BLOCK_READ);
600 if (rv != APR_SUCCESS) {
603 /* reading may have split the bucket, so recompute next: */
604 next = APR_BUCKET_NEXT(bucket);
605 vec[nvec].iov_base = (char *)data;
606 vec[nvec].iov_len = length;
608 if (nvec == MAX_IOVEC_TO_WRITE) {
609 rv = writev_nonblocking(s, vec, nvec, bb, bytes_written, c);
611 if (rv != APR_SUCCESS) {
620 rv = writev_nonblocking(s, vec, nvec, bb, bytes_written, c);
621 if (rv != APR_SUCCESS) {
626 remove_empty_buckets(bb);
631 static void remove_empty_buckets(apr_bucket_brigade *bb)
634 while (((bucket = APR_BRIGADE_FIRST(bb)) != APR_BRIGADE_SENTINEL(bb)) &&
635 (APR_BUCKET_IS_METADATA(bucket) || (bucket->length == 0))) {
636 APR_BUCKET_REMOVE(bucket);
637 apr_bucket_destroy(bucket);
641 static apr_status_t send_brigade_blocking(apr_socket_t *s,
642 apr_bucket_brigade *bb,
643 apr_size_t *bytes_written,
649 while (!APR_BRIGADE_EMPTY(bb)) {
650 rv = send_brigade_nonblocking(s, bb, bytes_written, c);
651 if (rv != APR_SUCCESS) {
652 if (APR_STATUS_IS_EAGAIN(rv)) {
653 /* Wait until we can send more data */
655 apr_interval_time_t timeout;
656 apr_pollfd_t pollset;
659 pollset.desc_type = APR_POLL_SOCKET;
660 pollset.reqevents = APR_POLLOUT;
662 apr_socket_timeout_get(s, &timeout);
663 rv = apr_poll(&pollset, 1, &nsds, timeout);
664 if (rv != APR_SUCCESS) {
676 static apr_status_t writev_nonblocking(apr_socket_t *s,
677 struct iovec *vec, apr_size_t nvec,
678 apr_bucket_brigade *bb,
679 apr_size_t *cumulative_bytes_written,
682 apr_status_t rv = APR_SUCCESS, arv;
683 apr_size_t bytes_written = 0, bytes_to_write = 0;
684 apr_size_t i, offset;
685 apr_interval_time_t old_timeout;
687 arv = apr_socket_timeout_get(s, &old_timeout);
688 if (arv != APR_SUCCESS) {
691 arv = apr_socket_timeout_set(s, 0);
692 if (arv != APR_SUCCESS) {
696 for (i = 0; i < nvec; i++) {
697 bytes_to_write += vec[i].iov_len;
700 while (bytes_written < bytes_to_write) {
702 rv = apr_socket_sendv(s, vec + offset, nvec - offset, &n);
705 for (i = offset; i < nvec; ) {
706 apr_bucket *bucket = APR_BRIGADE_FIRST(bb);
707 if (APR_BUCKET_IS_METADATA(bucket)) {
708 APR_BUCKET_REMOVE(bucket);
709 apr_bucket_destroy(bucket);
711 else if (n >= vec[i].iov_len) {
712 APR_BUCKET_REMOVE(bucket);
713 apr_bucket_destroy(bucket);
715 n -= vec[i++].iov_len;
718 apr_bucket_split(bucket, n);
719 APR_BUCKET_REMOVE(bucket);
720 apr_bucket_destroy(bucket);
722 vec[i].iov_base = (char *) vec[i].iov_base + n;
727 if (rv != APR_SUCCESS) {
731 if ((ap__logio_add_bytes_out != NULL) && (bytes_written > 0)) {
732 ap__logio_add_bytes_out(c, bytes_written);
734 *cumulative_bytes_written += bytes_written;
736 arv = apr_socket_timeout_set(s, old_timeout);
737 if ((arv != APR_SUCCESS) && (rv == APR_SUCCESS)) {
747 static apr_status_t sendfile_nonblocking(apr_socket_t *s,
749 apr_size_t *cumulative_bytes_written,
752 apr_status_t rv = APR_SUCCESS;
753 apr_bucket_file *file_bucket;
755 apr_size_t file_length;
756 apr_off_t file_offset;
757 apr_size_t bytes_written = 0;
759 if (!APR_BUCKET_IS_FILE(bucket)) {
760 ap_log_error(APLOG_MARK, APLOG_ERR, rv, c->base_server,
761 "core_filter: sendfile_nonblocking: "
762 "this should never happen");
765 file_bucket = (apr_bucket_file *)(bucket->data);
766 fd = file_bucket->fd;
767 file_length = bucket->length;
768 file_offset = bucket->start;
770 if (bytes_written < file_length) {
771 apr_size_t n = file_length - bytes_written;
773 apr_interval_time_t old_timeout;
775 arv = apr_socket_timeout_get(s, &old_timeout);
776 if (arv != APR_SUCCESS) {
779 arv = apr_socket_timeout_set(s, 0);
780 if (arv != APR_SUCCESS) {
783 rv = apr_socket_sendfile(s, fd, NULL, &file_offset, &n, 0);
784 if (rv == APR_SUCCESS) {
788 arv = apr_socket_timeout_set(s, old_timeout);
789 if ((arv != APR_SUCCESS) && (rv == APR_SUCCESS)) {
793 if ((ap__logio_add_bytes_out != NULL) && (bytes_written > 0)) {
794 ap__logio_add_bytes_out(c, bytes_written);
796 *cumulative_bytes_written += bytes_written;
797 if ((bytes_written < file_length) && (bytes_written > 0)) {
798 apr_bucket_split(bucket, bytes_written);
799 APR_BUCKET_REMOVE(bucket);
800 apr_bucket_destroy(bucket);
802 else if (bytes_written == file_length) {
803 APR_BUCKET_REMOVE(bucket);
804 apr_bucket_destroy(bucket);