| 4841 | } |
| 4842 | |
| 4843 | PROXY_DECLARE(int) ap_proxy_prefetch_input(request_rec *r, |
| 4844 | proxy_conn_rec *backend, |
| 4845 | apr_bucket_brigade *input_brigade, |
| 4846 | apr_read_type_e block, |
| 4847 | apr_off_t *bytes_read, |
| 4848 | apr_off_t max_read) |
| 4849 | { |
| 4850 | apr_pool_t *p = r->pool; |
| 4851 | conn_rec *c = r->connection; |
| 4852 | apr_bucket_brigade *temp_brigade; |
| 4853 | apr_status_t status; |
| 4854 | apr_off_t bytes; |
| 4855 | |
| 4856 | *bytes_read = 0; |
| 4857 | if (max_read < APR_BUCKET_BUFF_SIZE) { |
| 4858 | max_read = APR_BUCKET_BUFF_SIZE; |
| 4859 | } |
| 4860 | |
| 4861 | /* Prefetch max_read bytes |
| 4862 | * |
| 4863 | * This helps us avoid any election of C-L v.s. T-E |
| 4864 | * request bodies, since we are willing to keep in |
| 4865 | * memory this much data, in any case. This gives |
| 4866 | * us an instant C-L election if the body is of some |
| 4867 | * reasonable size. |
| 4868 | */ |
| 4869 | temp_brigade = apr_brigade_create(p, input_brigade->bucket_alloc); |
| 4870 | |
| 4871 | /* Account for saved input, if any. */ |
| 4872 | apr_brigade_length(input_brigade, 0, bytes_read); |
| 4873 | |
| 4874 | /* Ensure we don't hit a wall where we have a buffer too small for |
| 4875 | * ap_get_brigade's filters to fetch us another bucket, surrender |
| 4876 | * once we hit 80 bytes (an arbitrary value) less than max_read. |
| 4877 | */ |
| 4878 | while (*bytes_read < max_read - 80 |
| 4879 | && (APR_BRIGADE_EMPTY(input_brigade) |
| 4880 | || !APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade)))) { |
| 4881 | status = ap_get_brigade(r->input_filters, temp_brigade, |
| 4882 | AP_MODE_READBYTES, block, |
| 4883 | max_read - *bytes_read); |
| 4884 | /* ap_get_brigade may return success with an empty brigade |
| 4885 | * for a non-blocking read which would block |
| 4886 | */ |
| 4887 | if (block == APR_NONBLOCK_READ |
| 4888 | && ((status == APR_SUCCESS && APR_BRIGADE_EMPTY(temp_brigade)) |
| 4889 | || APR_STATUS_IS_EAGAIN(status))) { |
| 4890 | break; |
| 4891 | } |
| 4892 | if (status != APR_SUCCESS) { |
| 4893 | ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01095) |
| 4894 | "prefetch request body failed to %pI (%s)" |
| 4895 | " from %s (%s)", backend->addr, |
| 4896 | backend->hostname ? backend->hostname : "", |
| 4897 | c->client_ip, c->remote_host ? c->remote_host : ""); |
| 4898 | return ap_map_http_request_error(status, HTTP_BAD_REQUEST); |
| 4899 | } |
| 4900 |
no test coverage detected