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

(-)httpd-2.2.17/modules/proxy/mod_proxy_ajp.c.orig (-46 / +91 lines)
Lines 190-195 static int ap_proxy_ajp_request(apr_pool Link Here
190
    apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
190
    apr_size_t maxsize = AJP_MSG_BUFFER_SZ;
191
    int send_body = 0;
191
    int send_body = 0;
192
    apr_off_t content_length = 0;
192
    apr_off_t content_length = 0;
193
    int original_status = r->status;
194
    const char *original_status_line = r->status_line;
193
195
194
    if (psf->io_buffer_size_set)
196
    if (psf->io_buffer_size_set)
195
       maxsize = psf->io_buffer_size;
197
       maxsize = psf->io_buffer_size;
Lines 430-500 static int ap_proxy_ajp_request(apr_pool Link Here
430
                if (status != APR_SUCCESS) {
432
                if (status != APR_SUCCESS) {
431
                    backend_failed = 1;
433
                    backend_failed = 1;
432
                }
434
                }
435
                else if ((r->status == 401) && psf->error_override) {
436
                    const char *buf;
437
                    const char *wa = "WWW-Authenticate";
438
                    if ((buf = apr_table_get(r->headers_out, wa))) {
439
                        apr_table_set(r->err_headers_out, wa, buf);
440
                    } else {
441
                        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
442
                                     "ap_proxy_ajp_request: origin server "
443
                                     "sent 401 without WWW-Authenticate header");
444
                    }
445
                }
433
                headers_sent = 1;
446
                headers_sent = 1;
434
                break;
447
                break;
435
            case CMD_AJP13_SEND_BODY_CHUNK:
448
            case CMD_AJP13_SEND_BODY_CHUNK:
436
                /* AJP13_SEND_BODY_CHUNK: piece of data */
449
                /* AJP13_SEND_BODY_CHUNK: piece of data */
437
                status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
450
                status = ajp_parse_data(r, conn->data, &size, &send_body_chunk_buff);
438
                if (status == APR_SUCCESS) {
451
                if (status == APR_SUCCESS) {
439
                    /* AJP13_SEND_BODY_CHUNK with zero length
452
                    /* If we are overriding the errors, we can't put the content
440
                     * is explicit flush message
453
                     * of the page into the brigade.
441
                     */
454
                     */
442
                    if (size == 0) {
455
                    if (!psf->error_override || !ap_is_HTTP_ERROR(r->status)) {
443
                        if (headers_sent) {
456
                        /* AJP13_SEND_BODY_CHUNK with zero length
444
                            e = apr_bucket_flush_create(r->connection->bucket_alloc);
457
                         * is explicit flush message
445
                            APR_BRIGADE_INSERT_TAIL(output_brigade, e);
458
                         */
459
                        if (size == 0) {
460
                            if (headers_sent) {
461
                                e = apr_bucket_flush_create(r->connection->bucket_alloc);
462
                                APR_BRIGADE_INSERT_TAIL(output_brigade, e);
463
                            }
464
                            else {
465
                                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
466
                                             "Ignoring flush message received before headers");
467
                            }
446
                        }
468
                        }
447
                        else {
469
                        else {
448
                            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
470
                            apr_status_t rv;
449
                                 "Ignoring flush message received before headers");
471
450
                        }
472
                            /* Handle the case where the error document is itself reverse
451
                    }
473
                             * proxied and was successful. We must maintain any previous
452
                    else {
474
                             * error status so that an underlying error (eg HTTP_NOT_FOUND)
453
                        apr_status_t rv;
475
                             * doesn't become an HTTP_OK.
476
                             */
477
                            if (psf->error_override && !ap_is_HTTP_ERROR(r->status)
478
                                    && ap_is_HTTP_ERROR(original_status)) {
479
                                r->status = original_status;
480
                                r->status_line = original_status_line;
481
                            }
454
482
455
                        e = apr_bucket_transient_create(send_body_chunk_buff, size,
483
                            e = apr_bucket_transient_create(send_body_chunk_buff, size,
456
                                                    r->connection->bucket_alloc);
484
                                                        r->connection->bucket_alloc);
457
                        APR_BRIGADE_INSERT_TAIL(output_brigade, e);
458
459
                        if ((conn->worker->flush_packets == flush_on) ||
460
                            ((conn->worker->flush_packets == flush_auto) &&
461
                            ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
462
                                             conn->worker->flush_wait))
463
                                             != APR_SUCCESS) &&
464
                              APR_STATUS_IS_TIMEUP(rv))) {
465
                            e = apr_bucket_flush_create(r->connection->bucket_alloc);
466
                            APR_BRIGADE_INSERT_TAIL(output_brigade, e);
485
                            APR_BRIGADE_INSERT_TAIL(output_brigade, e);
486
487
                            if ((conn->worker->flush_packets == flush_on) ||
488
                                ((conn->worker->flush_packets == flush_auto) &&
489
                                ((rv = apr_poll(conn_poll, 1, &conn_poll_fd,
490
                                                 conn->worker->flush_wait))
491
                                                 != APR_SUCCESS) &&
492
                                  APR_STATUS_IS_TIMEUP(rv))) {
493
                                e = apr_bucket_flush_create(r->connection->bucket_alloc);
494
                                APR_BRIGADE_INSERT_TAIL(output_brigade, e);
495
                            }
496
                            apr_brigade_length(output_brigade, 0, &bb_len);
497
                            if (bb_len != -1)
498
                                conn->worker->s->read += bb_len;
467
                        }
499
                        }
468
                        apr_brigade_length(output_brigade, 0, &bb_len);
500
                        if (ap_pass_brigade(r->output_filters,
469
                        if (bb_len != -1)
501
                                            output_brigade) != APR_SUCCESS) {
470
                            conn->worker->s->read += bb_len;
502
                            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
471
                    }
503
                                          "proxy: error processing body.%s",
472
                    if (ap_pass_brigade(r->output_filters,
504
                                          r->connection->aborted ?
473
                                        output_brigade) != APR_SUCCESS) {
505
                                          " Client aborted connection." : "");
474
                        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
506
                            output_failed = 1;
475
                                      "proxy: error processing body.%s",
507
                        }
476
                                      r->connection->aborted ?
508
                        data_sent = 1;
477
                                      " Client aborted connection." : "");
509
                        apr_brigade_cleanup(output_brigade);
478
                        output_failed = 1;
479
                    }
510
                    }
480
                    data_sent = 1;
481
                    apr_brigade_cleanup(output_brigade);
482
                }
511
                }
483
                else {
512
                else {
484
                    backend_failed = 1;
513
                    backend_failed = 1;
485
                }
514
                }
486
                break;
515
                break;
487
            case CMD_AJP13_END_RESPONSE:
516
            case CMD_AJP13_END_RESPONSE:
488
                e = apr_bucket_eos_create(r->connection->bucket_alloc);
517
                /* If we are overriding the errors, we must not send anything to
489
                APR_BRIGADE_INSERT_TAIL(output_brigade, e);
518
                 * the client, especially as the brigade already contains headers.
490
                if (ap_pass_brigade(r->output_filters,
519
                 * So do nothing here, and it will be cleaned up below.
491
                                    output_brigade) != APR_SUCCESS) {
520
                 */
492
                    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
521
                if (!psf->error_override || !ap_is_HTTP_ERROR(r->status)) {
493
                                  "proxy: error processing end");
522
                    e = apr_bucket_eos_create(r->connection->bucket_alloc);
494
                    output_failed = 1;
523
                    APR_BRIGADE_INSERT_TAIL(output_brigade, e);
524
                    if (ap_pass_brigade(r->output_filters,
525
                                        output_brigade) != APR_SUCCESS) {
526
                        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
527
                                      "proxy: error processing end");
528
                        output_failed = 1;
529
                    }
530
                    /* XXX: what about flush here? See mod_jk */
531
                    data_sent = 1;
495
                }
532
                }
496
                /* XXX: what about flush here? See mod_jk */
497
                data_sent = 1;
498
                request_ended = 1;
533
                request_ended = 1;
499
                break;
534
                break;
500
            default:
535
            default:
Lines 569-575 static int ap_proxy_ajp_request(apr_pool Link Here
569
                     "proxy: got response from %pI (%s)",
604
                     "proxy: got response from %pI (%s)",
570
                     conn->worker->cp->addr,
605
                     conn->worker->cp->addr,
571
                     conn->worker->hostname);
606
                     conn->worker->hostname);
572
        rv = OK;
607
608
        if (psf->error_override && ap_is_HTTP_ERROR(r->status)) {
609
            /* clear r->status for override error, otherwise ErrorDocument
610
             * thinks that this is a recursive error, and doesn't find the
611
             * custom error page
612
             */
613
            rv = r->status;
614
            r->status = HTTP_OK;
615
        } else {
616
            rv = OK;
617
        }
573
    }
618
    }
574
619
575
    if (backend_failed) {
620
    if (backend_failed) {

Return to bug 50945