View | Details | Raw Unified | Return to bug 50945
Collapse All | Expand All

(-)httpd-2.2.22/modules/proxy/mod_proxy_ajp.c.orig (-47 / +92 lines)
Lines 191-196 static int ap_proxy_ajp_request(apr_pool Link Here
191
    apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
191
    apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
192
    int send_body = 0;
192
    int send_body = 0;
193
    apr_off_t content_length = 0;
193
    apr_off_t content_length = 0;
194
    int original_status = r->status;
195
    const char *original_status_line = r->status_line;
194
196
195
    if (psf->io_buffer_size_set)
197
    if (psf->io_buffer_size_set)
196
       maxsize = psf->io_buffer_size;
198
       maxsize = psf->io_buffer_size;
Lines 442-497 static int ap_proxy_ajp_request(apr_pool Link Here
442
                if (status != APR_SUCCESS) {
444
                if (status != APR_SUCCESS) {
443
                    backend_failed = 1;
445
                    backend_failed = 1;
444
                }
446
                }
447
                else if ((r->status == 401) && psf->error_override) {
448
                    const char *buf;
449
                    const char *wa = "WWW-Authenticate";
450
                    if ((buf = apr_table_get(r->headers_out, wa))) {
451
                        apr_table_set(r->err_headers_out, wa, buf);
452
                    } else {
453
                        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
454
                                     "ap_proxy_ajp_request: origin server "
455
                                     "sent 401 without WWW-Authenticate header");
456
                    }
457
                }
445
                headers_sent = 1;
458
                headers_sent = 1;
446
                break;
459
                break;
447
            case CMD_AJP13_SEND_BODY_CHUNK:
460
            case CMD_AJP13_SEND_BODY_CHUNK:
448
                /* AJP13_SEND_BODY_CHUNK: piece of data */
461
                /* AJP13_SEND_BODY_CHUNK: piece of data */
449
                status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
462
                status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
450
                if (status == APR_SUCCESS) {
463
                if (status == APR_SUCCESS) {
451
                    /* AJP13_SEND_BODY_CHUNK with zero length
464
                    /* If we are overriding the errors, we can't put the content
452
                     * is explicit flush message
465
                     * of the page into the brigade.
453
                     */
466
                     */
454
                    if (size == 0) {
467
                    if (!psf->error_override || !ap_is_HTTP_ERROR(r->status)) {
455
                        if (headers_sent) {
468
                        /* AJP13_SEND_BODY_CHUNK with zero length
456
                            e = apr_bucket_flush_create(r->connection->bucket_alloc);
469
                         * is explicit flush message
457
                            APR_BRIGADE_INSERT_TAIL(output_brigade, e);
470
                         */
471
                        if (size == 0) {
472
                            if (headers_sent) {
473
                                e = apr_bucket_flush_create(r->connection->bucket_alloc);
474
                                APR_BRIGADE_INSERT_TAIL(output_brigade, e);
475
                            }
476
                            else {
477
                                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
478
                                             "Ignoring flush message received before headers");
479
                            }
458
                        }
480
                        }
459
                        else {
481
                        else {
460
                            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
482
                            apr_status_t rv;
461
                                 "Ignoring flush message received before headers");
462
                        }
463
                    }
464
                    else {
465
                        apr_status_t rv;
466
483
467
                        e = apr_bucket_transient_create(send_body_chunk_buff, size,
484
                            /* Handle the case where the error document is itself reverse
468
                                                    r->connection->bucket_alloc);
485
                             * proxied and was successful. We must maintain any previous
469
                        APR_BRIGADE_INSERT_TAIL(output_brigade, e);
486
                             * error status so that an underlying error (eg HTTP_NOT_FOUND)
470
487
                             * doesn't become an HTTP_OK.
471
                        if ((conn->worker->flush_packets == flush_on) ||
488
                             */
472
                            ((conn->worker->flush_packets == flush_auto) &&
489
                            if (psf->error_override && !ap_is_HTTP_ERROR(r->status)
473
                            ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
490
                                    && ap_is_HTTP_ERROR(original_status)) {
474
                                             conn->worker->flush_wait))
491
                                r->status = original_status;
475
                                             != APR_SUCCESS) &&
492
                                r->status_line = original_status_line;
476
                              APR_STATUS_IS_TIMEUP(rv))) {
493
                            }
477
                            e = apr_bucket_flush_create(r->connection->bucket_alloc);
494
495
                            e = apr_bucket_transient_create(send_body_chunk_buff, size,
496
                                                        r->connection->bucket_alloc);
478
                            APR_BRIGADE_INSERT_TAIL(output_brigade, e);
497
                            APR_BRIGADE_INSERT_TAIL(output_brigade, e);
498
499
                            if ((conn->worker->flush_packets == flush_on) ||
500
                                ((conn->worker->flush_packets == flush_auto) &&
501
                                ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
502
                                                 conn->worker->flush_wait))
503
                                                 != APR_SUCCESS) &&
504
                                  APR_STATUS_IS_TIMEUP(rv))) {
505
                                e = apr_bucket_flush_create(r->connection->bucket_alloc);
506
                                APR_BRIGADE_INSERT_TAIL(output_brigade, e);
507
                            }
508
                            apr_brigade_length(output_brigade, 0, &bb_len);
509
                            if (bb_len != -1)
510
                                conn->worker->s->read += bb_len;
479
                        }
511
                        }
480
                        apr_brigade_length(output_brigade, 0, &bb_len);
512
                        if (headers_sent) {
481
                        if (bb_len != -1)
513
                            if (ap_pass_brigade(r->output_filters,
482
                            conn->worker->s->read += bb_len;
514
                                                output_brigade) != APR_SUCCESS) {
483
                    }
515
                                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
484
                    if (headers_sent) {
516
                                              "proxy: error processing body.%s",
485
                        if (ap_pass_brigade(r->output_filters,
517
                                              r->connection->aborted ?
486
                                            output_brigade) != APR_SUCCESS) {
518
                                              " Client aborted connection." : "");
487
                            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
519
                                output_failed = 1;
488
                                          "proxy: error processing body.%s",
520
                            }
489
                                          r->connection->aborted ?
521
                            data_sent = 1;
490
                                          " Client aborted connection." : "");
522
                            apr_brigade_cleanup(output_brigade);
491
                            output_failed = 1;
492
                        }
523
                        }
493
                        data_sent = 1;
494
                        apr_brigade_cleanup(output_brigade);
495
                    }
524
                    }
496
                }
525
                }
497
                else {
526
                else {
Lines 503-518 static int ap_proxy_ajp_request(apr_pool Link Here
503
                if (status != APR_SUCCESS) {
532
                if (status != APR_SUCCESS) {
504
                    backend_failed = 1;
533
                    backend_failed = 1;
505
                }
534
                }
506
                e = apr_bucket_eos_create(r->connection->bucket_alloc);
535
                /* If we are overriding the errors, we must not send anything to
507
                APR_BRIGADE_INSERT_TAIL(output_brigade, e);
536
                 * the client, especially as the brigade already contains headers.
508
                if (ap_pass_brigade(r->output_filters,
537
                 * So do nothing here, and it will be cleaned up below.
509
                                    output_brigade) != APR_SUCCESS) {
538
                 */
510
                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
539
                if (!psf->error_override || !ap_is_HTTP_ERROR(r->status)) {
511
                                  "proxy: error processing end");
540
                    e = apr_bucket_eos_create(r->connection->bucket_alloc);
512
                    output_failed = 1;
541
                    APR_BRIGADE_INSERT_TAIL(output_brigade, e);
542
                    if (ap_pass_brigade(r->output_filters,
543
                                        output_brigade) != APR_SUCCESS) {
544
                        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
545
                                      "proxy: error processing end");
546
                        output_failed = 1;
547
                    }
548
                    /* XXX: what about flush here? See mod_jk */
549
                    data_sent = 1;
513
                }
550
                }
514
                /* XXX: what about flush here? See mod_jk */
515
                data_sent = 1;
516
                request_ended = 1;
551
                request_ended = 1;
517
                break;
552
                break;
518
            default:
553
            default:
Lines 591-597 static int ap_proxy_ajp_request(apr_pool Link Here
591
                     "proxy: got response from %pI (%s)",
626
                     "proxy: got response from %pI (%s)",
592
                     conn->worker->cp->addr,
627
                     conn->worker->cp->addr,
593
                     conn->worker->hostname);
628
                     conn->worker->hostname);
594
        rv = OK;
629
630
        if (psf->error_override && ap_is_HTTP_ERROR(r->status)) {
631
            /* clear r->status for override error, otherwise ErrorDocument
632
             * thinks that this is a recursive error, and doesn't find the
633
             * custom error page
634
             */
635
            rv = r->status;
636
            r->status = HTTP_OK;
637
        } else {
638
            rv = OK;
639
        }
595
    }
640
    }
596
641
597
    if (backend_failed) {
642
    if (backend_failed) {

Return to bug 50945