~ubuntu-branches/ubuntu/jaunty/apache2/jaunty-proposed

« back to all changes in this revision

Viewing changes to modules/proxy/mod_proxy_http.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-12-15 00:06:50 UTC
  • mfrom: (14.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20081215000650-5ovq2vvvrtmn5r1l
Tags: 2.2.11-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/{control, rules}: enable PIE hardening.
  - debian/{control, rules, apache2.2-common.ufw.profile}: add ufw profiles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
699
699
    if (apr_table_get(r->subprocess_env, "force-proxy-request-1.0")) {
700
700
        buf = apr_pstrcat(p, r->method, " ", url, " HTTP/1.0" CRLF, NULL);
701
701
        force10 = 1;
 
702
        /*
 
703
         * According to RFC 2616 8.2.3 we are not allowed to forward an
 
704
         * Expect: 100-continue to an HTTP/1.0 server. Instead we MUST return
 
705
         * a HTTP_EXPECTATION_FAILED
 
706
         */
 
707
        if (r->expecting_100) {
 
708
            return HTTP_EXPECTATION_FAILED;
 
709
        }
702
710
        p_conn->close++;
703
711
    } else {
704
712
        buf = apr_pstrcat(p, r->method, " ", url, " HTTP/1.1" CRLF, NULL);
1330
1338
    request_rec *rp;
1331
1339
    apr_bucket *e;
1332
1340
    apr_bucket_brigade *bb, *tmp_bb;
 
1341
    apr_bucket_brigade *pass_bb;
1333
1342
    int len, backasswards;
1334
1343
    int interim_response = 0; /* non-zero whilst interim 1xx responses
1335
1344
                               * are being read. */
1342
1351
    const char *te = NULL;
1343
1352
 
1344
1353
    bb = apr_brigade_create(p, c->bucket_alloc);
 
1354
    pass_bb = apr_brigade_create(p, c->bucket_alloc);
1345
1355
 
1346
1356
    /* Get response from the remote server, and pass it up the
1347
1357
     * filter chain
1367
1377
            ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r,
1368
1378
                          "proxy: error reading status line from remote "
1369
1379
                          "server %s", backend->hostname);
 
1380
            if (rc == APR_TIMEUP) {
 
1381
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
 
1382
                              "proxy: read timeout");
 
1383
            }
1370
1384
            /*
1371
1385
             * If we are a reverse proxy request shutdown the connection
1372
1386
             * WITHOUT ANY response to trigger a retry by the client
1374
1388
             * BUT currently we should not do this if the request is the
1375
1389
             * first request on a keepalive connection as browsers like
1376
1390
             * seamonkey only display an empty page in this case and do
1377
 
             * not do a retry.
 
1391
             * not do a retry. We should also not do this on a
 
1392
             * connection which times out; instead handle as
 
1393
             * we normally would handle timeouts
1378
1394
             */
1379
 
            if (r->proxyreq == PROXYREQ_REVERSE && c->keepalives) {
 
1395
            if (r->proxyreq == PROXYREQ_REVERSE && c->keepalives &&
 
1396
                rc != APR_TIMEUP) {
1380
1397
                apr_bucket *eos;
1381
1398
 
1382
1399
                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
1753
1770
                        break;
1754
1771
                    }
1755
1772
 
 
1773
                    /* Switch the allocator lifetime of the buckets */
 
1774
                    ap_proxy_buckets_lifetime_transform(r, bb, pass_bb);
 
1775
 
1756
1776
                    /* found the last brigade? */
1757
1777
                    if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(bb))) {
1758
1778
                        /* signal that we must leave */
1760
1780
                    }
1761
1781
 
1762
1782
                    /* try send what we read */
1763
 
                    if (ap_pass_brigade(r->output_filters, bb) != APR_SUCCESS
 
1783
                    if (ap_pass_brigade(r->output_filters, pass_bb) != APR_SUCCESS
1764
1784
                        || c->aborted) {
1765
1785
                        /* Ack! Phbtt! Die! User aborted! */
1766
1786
                        backend->close = 1;  /* this causes socket close below */
1769
1789
 
1770
1790
                    /* make sure we always clean up after ourselves */
1771
1791
                    apr_brigade_cleanup(bb);
 
1792
                    apr_brigade_cleanup(pass_bb);
1772
1793
 
1773
1794
                } while (!finish);
1774
1795
            }
1857
1878
    const char *u;
1858
1879
    proxy_conn_rec *backend = NULL;
1859
1880
    int is_ssl = 0;
1860
 
 
1861
 
    /* Note: Memory pool allocation.
1862
 
     * A downstream keepalive connection is always connected to the existence
1863
 
     * (or not) of an upstream keepalive connection. If this is not done then
1864
 
     * load balancing against multiple backend servers breaks (one backend
1865
 
     * server ends up taking 100% of the load), and the risk is run of
1866
 
     * downstream keepalive connections being kept open unnecessarily. This
1867
 
     * keeps webservers busy and ties up resources.
1868
 
     *
1869
 
     * As a result, we allocate all sockets out of the upstream connection
1870
 
     * pool, and when we want to reuse a socket, we check first whether the
1871
 
     * connection ID of the current upstream connection is the same as that
1872
 
     * of the connection when the socket was opened.
 
1881
    conn_rec *c = r->connection;
 
1882
    /*
 
1883
     * Use a shorter-lived pool to reduce memory usage
 
1884
     * and avoid a memory leak
1873
1885
     */
1874
 
    apr_pool_t *p = r->connection->pool;
1875
 
    conn_rec *c = r->connection;
1876
 
    apr_uri_t *uri = apr_palloc(r->connection->pool, sizeof(*uri));
 
1886
    apr_pool_t *p = r->pool;
 
1887
    apr_uri_t *uri = apr_palloc(p, sizeof(*uri));
1877
1888
 
1878
1889
    /* find the scheme */
1879
1890
    u = strchr(url, ':');
1881
1892
       return DECLINED;
1882
1893
    if ((u - url) > 14)
1883
1894
        return HTTP_BAD_REQUEST;
1884
 
    scheme = apr_pstrndup(c->pool, url, u - url);
 
1895
    scheme = apr_pstrndup(p, url, u - url);
1885
1896
    /* scheme is lowercase */
1886
1897
    ap_str_tolower(scheme);
1887
1898
    /* is it for us? */
1921
1932
        ap_proxy_ssl_connection_cleanup(backend, r);
1922
1933
    }
1923
1934
 
 
1935
    /*
 
1936
     * In the case that we are handling a reverse proxy connection and this
 
1937
     * is not a request that is coming over an already kept alive connection
 
1938
     * with the client, do NOT reuse the connection to the backend, because
 
1939
     * we cannot forward a failure to the client in this case as the client
 
1940
     * does NOT expects this in this situation.
 
1941
     * Yes, this creates a performance penalty.
 
1942
     */
 
1943
    if ((r->proxyreq == PROXYREQ_REVERSE) && (!c->keepalives)
 
1944
        && (apr_table_get(r->subprocess_env, "proxy-initial-not-pooled"))) {
 
1945
        backend->close = 1;
 
1946
    }
 
1947
 
1924
1948
    /* Step One: Determine Who To Connect To */
1925
1949
    if ((status = ap_proxy_determine_connection(p, r, conf, worker, backend,
1926
1950
                                                uri, &url, proxyname,