| 4969 | } |
| 4970 | |
| 4971 | PROXY_DECLARE(int) ap_proxy_spool_input(request_rec *r, |
| 4972 | proxy_conn_rec *backend, |
| 4973 | apr_bucket_brigade *input_brigade, |
| 4974 | apr_off_t *bytes_spooled, |
| 4975 | apr_off_t max_mem_spool) |
| 4976 | { |
| 4977 | apr_pool_t *p = r->pool; |
| 4978 | int seen_eos = 0, rv = OK; |
| 4979 | apr_status_t status = APR_SUCCESS; |
| 4980 | apr_bucket_alloc_t *bucket_alloc = input_brigade->bucket_alloc; |
| 4981 | apr_bucket_brigade *body_brigade; |
| 4982 | apr_bucket *e; |
| 4983 | apr_off_t bytes, fsize = 0; |
| 4984 | apr_file_t *tmpfile = NULL; |
| 4985 | |
| 4986 | *bytes_spooled = 0; |
| 4987 | body_brigade = apr_brigade_create(p, bucket_alloc); |
| 4988 | |
| 4989 | do { |
| 4990 | if (APR_BRIGADE_EMPTY(input_brigade)) { |
| 4991 | rv = ap_proxy_read_input(r, backend, input_brigade, |
| 4992 | HUGE_STRING_LEN); |
| 4993 | if (rv != OK) { |
| 4994 | return rv; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | /* If this brigade contains EOS, either stop or remove it. */ |
| 4999 | if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(input_brigade))) { |
| 5000 | seen_eos = 1; |
| 5001 | } |
| 5002 | |
| 5003 | apr_brigade_length(input_brigade, 1, &bytes); |
| 5004 | |
| 5005 | if (*bytes_spooled + bytes > max_mem_spool) { |
| 5006 | /* can't spool any more in memory; write latest brigade to disk */ |
| 5007 | if (tmpfile == NULL) { |
| 5008 | const char *temp_dir; |
| 5009 | char *template; |
| 5010 | |
| 5011 | status = apr_temp_dir_get(&temp_dir, p); |
| 5012 | if (status != APR_SUCCESS) { |
| 5013 | ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01089) |
| 5014 | "search for temporary directory failed"); |
| 5015 | return HTTP_INTERNAL_SERVER_ERROR; |
| 5016 | } |
| 5017 | apr_filepath_merge(&template, temp_dir, |
| 5018 | "modproxy.tmp.XXXXXX", |
| 5019 | APR_FILEPATH_NATIVE, p); |
| 5020 | status = apr_file_mktemp(&tmpfile, template, 0, p); |
| 5021 | if (status != APR_SUCCESS) { |
| 5022 | ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, APLOGNO(01090) |
| 5023 | "creation of temporary file in directory " |
| 5024 | "%s failed", temp_dir); |
| 5025 | return HTTP_INTERNAL_SERVER_ERROR; |
| 5026 | } |
| 5027 | } |
| 5028 | for (e = APR_BRIGADE_FIRST(input_brigade); |
no test coverage detected