You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ngx_http_uploadprogress_module.c 38KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. /*
  2. * Copyright (C) 2007 Brice Figureau
  3. * shm_zone and rbtree code Copyright (c) 2002-2007 Igor Sysoev
  4. */
  5. #include <ngx_config.h>
  6. #include <ngx_core.h>
  7. #include <ngx_http.h>
  8. #define TIMER_FREQUENCY 15 * 1000
  9. typedef struct ngx_http_uploadprogress_node_s ngx_http_uploadprogress_node_t;
  10. struct ngx_http_uploadprogress_node_s {
  11. ngx_rbtree_node_t node;
  12. ngx_uint_t err_status;
  13. off_t rest;
  14. off_t length;
  15. ngx_uint_t done;
  16. time_t timeout;
  17. struct ngx_http_uploadprogress_node_s *prev;
  18. struct ngx_http_uploadprogress_node_s *next;
  19. u_char len;
  20. u_char data[1];
  21. };
  22. typedef struct {
  23. ngx_shm_zone_t *shm_zone;
  24. ngx_rbtree_node_t *node;
  25. time_t timeout;
  26. } ngx_http_uploadprogress_cleanup_t;
  27. typedef struct {
  28. ngx_rbtree_t *rbtree;
  29. ngx_http_uploadprogress_node_t list_head;
  30. ngx_http_uploadprogress_node_t list_tail;
  31. } ngx_http_uploadprogress_ctx_t;
  32. typedef struct {
  33. ngx_shm_zone_t *shm_zone;
  34. time_t timeout;
  35. ngx_event_t cleanup;
  36. ngx_http_handler_pt handler;
  37. u_char track;
  38. } ngx_http_uploadprogress_conf_t;
  39. typedef struct {
  40. ngx_http_event_handler_pt read_event_handler;
  41. } ngx_http_uploadprogress_module_ctx_t;
  42. static ngx_int_t ngx_http_reportuploads_handler(ngx_http_request_t *r);
  43. static void ngx_http_uploadprogress_cleanup(void *data);
  44. static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
  45. static ngx_int_t ngx_http_uploadprogress_init_zone(ngx_shm_zone_t * shm_zone, void *data);
  46. static ngx_int_t ngx_http_uploadprogress_init(ngx_conf_t * cf);
  47. static void *ngx_http_uploadprogress_create_loc_conf(ngx_conf_t *cf);
  48. static char *ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
  49. static char *ngx_http_track_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
  50. static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
  51. static char *ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
  52. static void ngx_clean_old_connections(ngx_event_t * ev);
  53. static ngx_int_t ngx_http_uploadprogress_content_handler(ngx_http_request_t *r);
  54. static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
  55. static ngx_command_t ngx_http_uploadprogress_commands[] = {
  56. {ngx_string("upload_progress"),
  57. NGX_HTTP_MAIN_CONF | NGX_CONF_TAKE2,
  58. ngx_http_upload_progress,
  59. 0,
  60. 0,
  61. NULL},
  62. {ngx_string("track_uploads"),
  63. NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_TAKE2,
  64. ngx_http_track_uploads,
  65. NGX_HTTP_LOC_CONF_OFFSET,
  66. 0,
  67. NULL},
  68. {ngx_string("report_uploads"),
  69. NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_TAKE1,
  70. ngx_http_report_uploads,
  71. NGX_HTTP_LOC_CONF_OFFSET,
  72. 0,
  73. NULL},
  74. ngx_null_command
  75. };
  76. static ngx_http_module_t ngx_http_uploadprogress_module_ctx = {
  77. NULL, /* preconfiguration */
  78. ngx_http_uploadprogress_init, /* postconfiguration */
  79. NULL, /* create main configuration */
  80. NULL, /* init main configuration */
  81. NULL, /* create server configuration */
  82. NULL, /* merge server configuration */
  83. ngx_http_uploadprogress_create_loc_conf, /* create location configuration */
  84. ngx_http_uploadprogress_merge_loc_conf /* merge location configuration */
  85. };
  86. ngx_module_t ngx_http_uploadprogress_module = {
  87. NGX_MODULE_V1,
  88. &ngx_http_uploadprogress_module_ctx, /* module context */
  89. ngx_http_uploadprogress_commands, /* module directives */
  90. NGX_HTTP_MODULE, /* module type */
  91. NULL, /* init master */
  92. NULL, /* init module */
  93. NULL, /* init process */
  94. NULL, /* init thread */
  95. NULL, /* exit thread */
  96. NULL, /* exit process */
  97. NULL, /* exit master */
  98. NGX_MODULE_V1_PADDING
  99. };
  100. static ngx_str_t x_progress_id = ngx_string("X-Progress-ID");
  101. static ngx_str_t*
  102. get_tracking_id(ngx_http_request_t * r)
  103. {
  104. u_char *p, *start_p;
  105. ngx_uint_t i;
  106. ngx_list_part_t *part;
  107. ngx_table_elt_t *header;
  108. ngx_str_t *ret;
  109. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: get_tracking_id");
  110. part = &r->headers_in.headers.part;
  111. header = part->elts;
  112. for (i = 0; /* void */ ; i++) {
  113. if (i >= part->nelts) {
  114. if (part->next == NULL) {
  115. break;
  116. }
  117. part = part->next;
  118. header = part->elts;
  119. i = 0;
  120. }
  121. if (header[i].key.len == x_progress_id.len
  122. && ngx_strncasecmp(header[i].key.data, x_progress_id.data,
  123. header[i].key.len) == 0) {
  124. ret = ngx_pcalloc(r->pool, sizeof(ngx_str_t));
  125. ret->data = header[i].value.data;
  126. ret->len = header[i].value.len;
  127. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  128. "upload-progress: get_tracking_id found header: %V", ret);
  129. return ret;
  130. }
  131. }
  132. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  133. "upload-progress: get_tracking_id no header found");
  134. /* not found, check as a reaquest arg */
  135. if (r->args.len) {
  136. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  137. "upload-progress: get_tracking_id no header found but args present");
  138. i = 0;
  139. p = r->args.data;
  140. do {
  141. ngx_uint_t len = r->args.len - (p - r->args.data);
  142. if (len >= 14 && ngx_strncasecmp(p, (u_char*)"X-Progress-ID=", 14) == 0) {
  143. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  144. "upload-progress: get_tracking_id found args: %s",p);
  145. i = 1;
  146. break;
  147. }
  148. if (len<=0)
  149. break;
  150. }
  151. while(p++);
  152. if (i) {
  153. start_p = p += 14;
  154. while (p < r->args.data + r->args.len) {
  155. if (*p++ != '&') {
  156. continue;
  157. }
  158. }
  159. ret = ngx_pcalloc(r->pool, sizeof(ngx_str_t));
  160. ret->data = start_p;
  161. ret->len = p - start_p;
  162. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  163. "upload-progress: get_tracking_id found args: %V",ret);
  164. return ret;
  165. }
  166. }
  167. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  168. "upload-progress: get_tracking_id no id found");
  169. return NULL;
  170. }
  171. static ngx_http_uploadprogress_node_t *
  172. find_node(ngx_str_t * id, ngx_http_uploadprogress_ctx_t * ctx, ngx_log_t * log)
  173. {
  174. uint32_t hash;
  175. ngx_rbtree_node_t *node, *sentinel;
  176. ngx_int_t rc;
  177. ngx_http_uploadprogress_node_t *up;
  178. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: find_node %V", id);
  179. hash = ngx_crc32_short(id->data, id->len);
  180. node = ctx->rbtree->root;
  181. sentinel = ctx->rbtree->sentinel;
  182. while (node != sentinel) {
  183. if (hash < node->key) {
  184. node = node->left;
  185. continue;
  186. }
  187. if (hash > node->key) {
  188. node = node->right;
  189. continue;
  190. }
  191. /* hash == node->key */
  192. do {
  193. up = (ngx_http_uploadprogress_node_t *) node;
  194. rc = ngx_memn2cmp(id->data, up->data, id->len, (size_t) up->len);
  195. if (rc == 0) {
  196. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0,
  197. "upload-progress: found node");
  198. return up;
  199. }
  200. node = (rc < 0) ? node->left : node->right;
  201. } while (node != sentinel && hash == node->key);
  202. break;
  203. }
  204. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "upload-progress: can't find node");
  205. return NULL;
  206. }
  207. static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r);
  208. static ngx_int_t
  209. ngx_http_uploadprogress_content_handler(ngx_http_request_t *r)
  210. {
  211. ngx_int_t rc;
  212. ngx_http_uploadprogress_module_ctx_t *ctx;
  213. ngx_http_uploadprogress_conf_t *upcf;
  214. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_content_handler");
  215. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  216. /* call the original request handler */
  217. rc = upcf->handler(r);
  218. /* bail out if error */
  219. if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
  220. return rc;
  221. }
  222. /* request is OK, hijack the read_event_handler */
  223. ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uploadprogress_module_ctx_t));
  224. if (ctx == NULL) {
  225. return NGX_ERROR;
  226. }
  227. ngx_http_set_ctx(r, ctx, ngx_http_uploadprogress_module);
  228. r->read_event_handler = ngx_http_uploadprogress_event_handler;
  229. return rc;
  230. }
  231. static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
  232. {
  233. ngx_str_t *id;
  234. ngx_slab_pool_t *shpool;
  235. ngx_connection_t *c;
  236. ngx_http_uploadprogress_ctx_t *ctx;
  237. ngx_http_uploadprogress_node_t *up;
  238. ngx_http_uploadprogress_conf_t *upcf;
  239. ngx_http_uploadprogress_module_ctx_t *module_ctx;
  240. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
  241. c = r->connection;
  242. /* call the original read event handler */
  243. module_ctx = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
  244. module_ctx->read_event_handler(r);
  245. /* check that the request/connection is still OK */
  246. if (r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE) {
  247. /* should mark up as error */
  248. id = get_tracking_id(r);
  249. if (id != NULL) {
  250. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  251. if (upcf != NULL && upcf->shm_zone != NULL) {
  252. ctx = upcf->shm_zone->data;
  253. /* get the original connection of the upload */
  254. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  255. ngx_shmtx_lock(&shpool->mutex);
  256. up = find_node(id, ctx, ngx_cycle->log);
  257. if (up != NULL) {
  258. up->err_status = r->headers_out.status;
  259. }
  260. ngx_shmtx_unlock(&shpool->mutex);
  261. }
  262. }
  263. return;
  264. }
  265. /* find node, update rest */
  266. id = get_tracking_id(r);
  267. if (id == NULL) {
  268. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
  269. "upload-progress: read_event_handler cant find id");
  270. return;
  271. }
  272. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
  273. "upload-progress: read_event_handler found id: %V", id);
  274. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  275. if (upcf->shm_zone == NULL) {
  276. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
  277. "upload-progress: read_event_handler no shm_zone for id: %V", id);
  278. return;
  279. }
  280. ctx = upcf->shm_zone->data;
  281. /* get the original connection of the upload */
  282. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  283. ngx_shmtx_lock(&shpool->mutex);
  284. up = find_node(id, ctx, r->connection->log);
  285. if (up != NULL && !up->done) {
  286. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  287. "upload-progress: read_event_handler found node: %V", id);
  288. up->rest = r->request_body->rest;
  289. up->length = r->headers_in.content_length_n;
  290. ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  291. "upload-progress: read_event_handler storing rest %uO/%uO for %V", up->rest, up->length, id);
  292. } else {
  293. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  294. "upload-progress: read_event_handler not found: %V", id);
  295. }
  296. ngx_shmtx_unlock(&shpool->mutex);
  297. }
  298. /* This generates the response for the report */
  299. static ngx_int_t
  300. ngx_http_reportuploads_handler(ngx_http_request_t * r)
  301. {
  302. ngx_str_t *id;
  303. ngx_buf_t *b;
  304. ngx_chain_t out;
  305. ngx_int_t rc, size, found=0, done=0, err_status=0;
  306. off_t rest=0, length=0;
  307. ngx_uint_t len, i;
  308. ngx_slab_pool_t *shpool;
  309. ngx_http_uploadprogress_conf_t *upcf;
  310. ngx_http_uploadprogress_ctx_t *ctx;
  311. ngx_http_uploadprogress_node_t *up;
  312. ngx_table_elt_t *expires, *cc, **ccp;
  313. if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
  314. return NGX_HTTP_NOT_ALLOWED;
  315. }
  316. rc = ngx_http_discard_request_body(r);
  317. if (rc != NGX_OK) {
  318. return rc;
  319. }
  320. /* get the tracking id if any */
  321. id = get_tracking_id(r);
  322. if (id == NULL) {
  323. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  324. "reportuploads handler cant find id");
  325. return NGX_DECLINED;
  326. }
  327. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  328. "reportuploads handler found id: %V", id);
  329. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  330. if (upcf->shm_zone == NULL) {
  331. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  332. "reportuploads no shm_zone for id: %V", id);
  333. return NGX_DECLINED;
  334. }
  335. ctx = upcf->shm_zone->data;
  336. /* get the original connection of the upload */
  337. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  338. ngx_shmtx_lock(&shpool->mutex);
  339. up = find_node(id, ctx, r->connection->log);
  340. if (up != NULL) {
  341. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  342. "reportuploads found node: %V", id);
  343. rest = up->rest;
  344. length = up->length;
  345. done = up->done;
  346. err_status = up->err_status;
  347. found = 1;
  348. } else {
  349. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  350. "reportuploads not found: %V", id);
  351. }
  352. ngx_shmtx_unlock(&shpool->mutex);
  353. /* send the output */
  354. r->headers_out.content_type.len = sizeof("text/javascript") - 1;
  355. r->headers_out.content_type.data = (u_char *) "text/javascript";
  356. /* force no-cache */
  357. expires = r->headers_out.expires;
  358. if (expires == NULL) {
  359. expires = ngx_list_push(&r->headers_out.headers);
  360. if (expires == NULL) {
  361. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  362. }
  363. r->headers_out.expires = expires;
  364. expires->hash = 1;
  365. expires->key.len = sizeof("Expires") - 1;
  366. expires->key.data = (u_char *) "Expires";
  367. }
  368. len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
  369. expires->value.len = len - 1;
  370. ccp = r->headers_out.cache_control.elts;
  371. if (ccp == NULL) {
  372. if (ngx_array_init(&r->headers_out.cache_control, r->pool,
  373. 1, sizeof(ngx_table_elt_t *))
  374. != NGX_OK) {
  375. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  376. }
  377. ccp = ngx_array_push(&r->headers_out.cache_control);
  378. if (ccp == NULL) {
  379. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  380. }
  381. cc = ngx_list_push(&r->headers_out.headers);
  382. if (cc == NULL) {
  383. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  384. }
  385. cc->hash = 1;
  386. cc->key.len = sizeof("Cache-Control") - 1;
  387. cc->key.data = (u_char *) "Cache-Control";
  388. *ccp = cc;
  389. } else {
  390. for (i = 1; i < r->headers_out.cache_control.nelts; i++) {
  391. ccp[i]->hash = 0;
  392. }
  393. cc = ccp[0];
  394. }
  395. expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
  396. cc->value.len = sizeof("no-cache") - 1;
  397. cc->value.data = (u_char *) "no-cache";
  398. if (r->method == NGX_HTTP_HEAD) {
  399. r->headers_out.status = NGX_HTTP_OK;
  400. rc = ngx_http_send_header(r);
  401. if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
  402. return rc;
  403. }
  404. }
  405. /*
  406. There are 4 possibilities
  407. * request not yet started: found = false
  408. * request in error: err_status >= NGX_HTTP_SPECIAL_RESPONSE
  409. * request finished: done = true
  410. * reauest in progress: rest > 0
  411. */
  412. if (!found) {
  413. size = sizeof("new Object({ 'state' : 'starting' })\r\n");
  414. } else if (err_status >= NGX_HTTP_SPECIAL_RESPONSE) {
  415. size = sizeof("new Object({ 'state' : 'error', 'status' : ") + NGX_INT_T_LEN + sizeof(" })\r\n");
  416. } else if (done) {
  417. size = sizeof("new Object({ 'state' : 'done' })\r\n");
  418. } else {
  419. size = sizeof("new Object({ 'state' : 'uploading', 'received' : ") + NGX_INT_T_LEN + sizeof(" })\r\n");
  420. size += sizeof(", 'size' : ") + NGX_INT_T_LEN;
  421. }
  422. b = ngx_create_temp_buf(r->pool, size);
  423. if (b == NULL) {
  424. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  425. }
  426. out.buf = b;
  427. out.next = NULL;
  428. if (!found) {
  429. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'starting' })\r\n",
  430. sizeof("new Object({ 'state' : 'starting' })\r\n") - 1);
  431. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "reportuploads returning starting");
  432. } else if (err_status >= NGX_HTTP_SPECIAL_RESPONSE) {
  433. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'error', 'status' : ",
  434. sizeof("new Object({ 'state' : 'error', 'status' : ") - 1);
  435. b->last = ngx_sprintf(b->last, "%ui })\r\n", err_status );
  436. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  437. "reportuploads returning error condition: %ui", err_status);
  438. } else if (done) {
  439. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'done' })\r\n",
  440. sizeof("new Object({ 'state' : 'done' })\r\n") - 1);
  441. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  442. "reportuploads returning done");
  443. } else {
  444. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'uploading', 'received' : ",
  445. sizeof("new Object({ 'state' : 'uploading', 'received' : ") - 1);
  446. b->last = ngx_sprintf(b->last, "%uO, 'size' : %uO })\r\n", (length - rest), length);
  447. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  448. "reportuploads returning %uO / %uO",(length - rest), length );
  449. }
  450. r->headers_out.status = NGX_HTTP_OK;
  451. r->headers_out.content_length_n = b->last - b->pos;
  452. b->last_buf = 1;
  453. rc = ngx_http_send_header(r);
  454. if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
  455. return rc;
  456. }
  457. return ngx_http_output_filter(r, &out);
  458. }
  459. /*
  460. Let's register the upload connection in our connections rb-tree
  461. */
  462. static ngx_int_t
  463. ngx_http_uploadprogress_handler(ngx_http_request_t * r)
  464. {
  465. size_t n;
  466. ngx_str_t *id;
  467. uint32_t hash;
  468. ngx_slab_pool_t *shpool;
  469. ngx_rbtree_node_t *node;
  470. ngx_http_uploadprogress_conf_t *upcf;
  471. ngx_http_uploadprogress_ctx_t *ctx;
  472. ngx_http_uploadprogress_node_t *up;
  473. ngx_http_uploadprogress_cleanup_t *upcln;
  474. ngx_pool_cleanup_t *cln;
  475. /* Is it a POST connection */
  476. if (r->method != NGX_HTTP_POST) {
  477. return NGX_DECLINED;
  478. }
  479. id = get_tracking_id(r);
  480. if (id == NULL) {
  481. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  482. "trackuploads no id found in POST upload req");
  483. return NGX_DECLINED;
  484. }
  485. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  486. "trackuploads id found: %V", id);
  487. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  488. if (!upcf->track) {
  489. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  490. "trackuploads not tracking in this location for id: %V", id);
  491. return NGX_DECLINED;
  492. }
  493. if (upcf->shm_zone == NULL) {
  494. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  495. "trackuploads no shm_zone for id: %V", id);
  496. return NGX_DECLINED;
  497. }
  498. ctx = upcf->shm_zone->data;
  499. hash = ngx_crc32_short(id->data, id->len);
  500. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  501. "trackuploads hash %08XD for id: %V", hash, id);
  502. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  503. ngx_shmtx_lock(&shpool->mutex);
  504. if (find_node(id, ctx, r->connection->log) != NULL) {
  505. ngx_shmtx_unlock(&shpool->mutex);
  506. /* already found a node with matching progress ID */
  507. ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
  508. "upload_progress: tracking already registered id: %V", id);
  509. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  510. }
  511. cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
  512. if (cln == NULL) {
  513. ngx_shmtx_unlock(&shpool->mutex);
  514. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  515. }
  516. n = sizeof(ngx_http_uploadprogress_node_t)
  517. + id->len;
  518. node = ngx_slab_alloc_locked(shpool, n);
  519. if (node == NULL) {
  520. ngx_shmtx_unlock(&shpool->mutex);
  521. return NGX_HTTP_SERVICE_UNAVAILABLE;
  522. }
  523. up = (ngx_http_uploadprogress_node_t *) node;
  524. node->key = hash;
  525. up->len = (u_char) id->len;
  526. up->err_status = r->err_status;
  527. up->next = ctx->list_head.next;
  528. up->next->prev = up;
  529. up->prev = &ctx->list_head;
  530. ctx->list_head.next = up;
  531. ngx_memcpy(up->data, id->data, id->len);
  532. ngx_rbtree_insert(ctx->rbtree, node);
  533. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  534. "trackuploads: %08XD inserted in rbtree", node->key);
  535. if (!upcf->cleanup.timer_set) {
  536. upcf->cleanup.data = upcf->shm_zone;
  537. upcf->cleanup.handler = ngx_clean_old_connections;
  538. upcf->cleanup.log = upcf->shm_zone->shm.log;
  539. ngx_add_timer(&upcf->cleanup, TIMER_FREQUENCY);
  540. }
  541. ngx_shmtx_unlock(&shpool->mutex);
  542. cln->handler = ngx_http_uploadprogress_cleanup;
  543. upcln = cln->data;
  544. upcln->shm_zone = upcf->shm_zone;
  545. upcln->node = node;
  546. upcln->timeout = upcf->timeout;
  547. /* start the timer if needed */
  548. return NGX_DECLINED;
  549. }
  550. static void
  551. ngx_http_uploadprogress_rbtree_insert_value(ngx_rbtree_node_t * temp,
  552. ngx_rbtree_node_t * node,
  553. ngx_rbtree_node_t * sentinel)
  554. {
  555. ngx_http_uploadprogress_node_t *upn, *upnt;
  556. for (;;) {
  557. if (node->key < temp->key) {
  558. if (temp->left == sentinel) {
  559. temp->left = node;
  560. break;
  561. }
  562. temp = temp->left;
  563. } else if (node->key > temp->key) {
  564. if (temp->right == sentinel) {
  565. temp->right = node;
  566. break;
  567. }
  568. temp = temp->right;
  569. } else { /* node->key == temp->key */
  570. upn = (ngx_http_uploadprogress_node_t *) node;
  571. upnt = (ngx_http_uploadprogress_node_t *) temp;
  572. if (ngx_memn2cmp(upn->data, upnt->data, upn->len, upnt->len) < 0) {
  573. if (temp->left == sentinel) {
  574. temp->left = node;
  575. break;
  576. }
  577. temp = temp->left;
  578. } else {
  579. if (temp->right == sentinel) {
  580. temp->right = node;
  581. break;
  582. }
  583. temp = temp->right;
  584. }
  585. }
  586. }
  587. node->parent = temp;
  588. node->left = sentinel;
  589. node->right = sentinel;
  590. ngx_rbt_red(node);
  591. }
  592. static void
  593. ngx_clean_old_connections(ngx_event_t * ev)
  594. {
  595. ngx_shm_zone_t *shm_zone;
  596. ngx_http_uploadprogress_ctx_t *ctx;
  597. ngx_slab_pool_t *shpool;
  598. ngx_rbtree_node_t *node;
  599. ngx_http_uploadprogress_node_t *up;
  600. time_t now = ngx_time();
  601. /* scan the rbtree */
  602. shm_zone = ev->data;
  603. ctx = shm_zone->data;
  604. shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
  605. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  606. "uploadprogress clean old connections at %T", now);
  607. ngx_shmtx_lock(&shpool->mutex);
  608. node = (ngx_rbtree_node_t *) ctx->list_tail.prev;
  609. for (;;) {
  610. if (node == &ctx->list_head.node) {
  611. break;
  612. }
  613. up = (ngx_http_uploadprogress_node_t *) node;
  614. ngx_log_debug3(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  615. "uploadprogress clean: scanning %08XD (req done %ui) timeout at %T",
  616. node->key, up->done, up->timeout);
  617. if (up->done && up->timeout < now) {
  618. up->next->prev = up->prev;
  619. up->prev->next = up->next;
  620. ngx_log_debug3(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  621. "uploadprogress clean: removing %08XD (req %ui) ",
  622. node->key, up->done, up->timeout);
  623. ngx_rbtree_delete(ctx->rbtree, node);
  624. ngx_slab_free_locked(shpool, node);
  625. }
  626. node = (ngx_rbtree_node_t *) up->prev;
  627. }
  628. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  629. "uploadprogress clean old connections restarting timer");
  630. ngx_add_timer(ev, TIMER_FREQUENCY); /* trigger again in 60s */
  631. ngx_shmtx_unlock(&shpool->mutex);
  632. }
  633. /*
  634. removes the expired node from the upload rbtree
  635. */
  636. static void
  637. ngx_http_uploadprogress_cleanup(void *data)
  638. {
  639. ngx_http_uploadprogress_cleanup_t *upcln = data;
  640. ngx_slab_pool_t *shpool;
  641. ngx_rbtree_node_t *node;
  642. ngx_http_uploadprogress_ctx_t *ctx;
  643. ngx_http_uploadprogress_node_t *up;
  644. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, upcln->shm_zone->shm.log, 0,
  645. "uploadprogress cleanup called");
  646. ctx = upcln->shm_zone->data;
  647. shpool = (ngx_slab_pool_t *) upcln->shm_zone->shm.addr;
  648. node = upcln->node;
  649. up = (ngx_http_uploadprogress_node_t *) node;
  650. ngx_shmtx_lock(&shpool->mutex);
  651. up->done = 1; /* mark the original request as done */
  652. up->timeout = ngx_time() + upcln->timeout; /* keep tracking for 60s */
  653. ngx_shmtx_unlock(&shpool->mutex);
  654. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, upcln->shm_zone->shm.log, 0,
  655. "uploadprogress cleanup: connection %08XD to be deleted at %T",
  656. node->key, up->timeout);
  657. }
  658. static ngx_int_t
  659. ngx_http_uploadprogress_init_zone(ngx_shm_zone_t * shm_zone, void *data)
  660. {
  661. ngx_http_uploadprogress_ctx_t *octx = data;
  662. ngx_slab_pool_t *shpool;
  663. ngx_rbtree_node_t *sentinel;
  664. ngx_http_uploadprogress_ctx_t *ctx;
  665. ctx = shm_zone->data;
  666. if (octx) {
  667. ctx->rbtree = octx->rbtree;
  668. return NGX_OK;
  669. }
  670. shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
  671. ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
  672. if (ctx->rbtree == NULL) {
  673. return NGX_ERROR;
  674. }
  675. sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
  676. if (sentinel == NULL) {
  677. return NGX_ERROR;
  678. }
  679. ngx_rbtree_sentinel_init(sentinel);
  680. ctx->rbtree->root = sentinel;
  681. ctx->rbtree->sentinel = sentinel;
  682. ctx->rbtree->insert = ngx_http_uploadprogress_rbtree_insert_value;
  683. return NGX_OK;
  684. }
  685. static ngx_int_t
  686. ngx_http_uploadprogress_errortracker(ngx_http_request_t * r)
  687. {
  688. size_t n;
  689. ngx_str_t *id;
  690. ngx_slab_pool_t *shpool;
  691. ngx_rbtree_node_t *node;
  692. ngx_http_uploadprogress_ctx_t *ctx;
  693. ngx_http_uploadprogress_node_t *up;
  694. ngx_http_uploadprogress_conf_t *upcf;
  695. uint32_t hash;
  696. ngx_http_uploadprogress_cleanup_t *upcln;
  697. ngx_pool_cleanup_t *cln;
  698. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  699. "uploadprogress error-tracker error: %D", r->err_status);
  700. if (r->err_status >= NGX_HTTP_SPECIAL_RESPONSE) {
  701. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  702. if (!upcf->track) {
  703. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  704. "uploadprogress error-tracker not tracking in this location");
  705. goto finish;
  706. }
  707. id = get_tracking_id(r);
  708. if (id == NULL) {
  709. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  710. "trackuploads error-tracker no id found in POST upload req");
  711. goto finish;
  712. }
  713. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  714. "trackuploads error-tracker id found: %V", id);
  715. if (upcf->shm_zone == NULL) {
  716. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  717. "trackuploads no shm_zone for id: %V", id);
  718. goto finish;
  719. }
  720. ctx = upcf->shm_zone->data;
  721. hash = ngx_crc32_short(id->data, id->len);
  722. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  723. "trackuploads error-tracking hash %08XD for id: %V", hash,
  724. id);
  725. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  726. ngx_shmtx_lock(&shpool->mutex);
  727. if ((up = find_node(id, ctx, r->connection->log)) != NULL) {
  728. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  729. "trackuploads error-tracking found node for id: %V", id);
  730. up->err_status = r->err_status;
  731. ngx_shmtx_unlock(&shpool->mutex);
  732. goto finish;
  733. }
  734. /* no lz found for this tracking id */
  735. n = sizeof(ngx_http_uploadprogress_node_t) + id->len;
  736. cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
  737. if (cln == NULL) {
  738. ngx_shmtx_unlock(&shpool->mutex);
  739. goto finish;
  740. }
  741. node = ngx_slab_alloc_locked(shpool, n);
  742. if (node == NULL) {
  743. ngx_shmtx_unlock(&shpool->mutex);
  744. goto finish;
  745. }
  746. up = (ngx_http_uploadprogress_node_t *) node;
  747. node->key = hash;
  748. up->len = (u_char) id->len;
  749. up->err_status = r->err_status;
  750. ngx_memcpy(up->data, id->data, id->len);
  751. up->next = ctx->list_head.next;
  752. up->next->prev = up;
  753. up->prev = &ctx->list_head;
  754. ctx->list_head.next = up;
  755. ngx_rbtree_insert(ctx->rbtree, node);
  756. /* start the timer if needed */
  757. if (!upcf->cleanup.timer_set) {
  758. upcf->cleanup.data = upcf->shm_zone;
  759. upcf->cleanup.handler = ngx_clean_old_connections;
  760. upcf->cleanup.log = upcf->shm_zone->shm.log;
  761. ngx_add_timer(&upcf->cleanup, TIMER_FREQUENCY);
  762. }
  763. ngx_shmtx_unlock(&shpool->mutex);
  764. cln->handler = ngx_http_uploadprogress_cleanup;
  765. upcln = cln->data;
  766. upcln->shm_zone = upcf->shm_zone;
  767. upcln->node = node;
  768. upcln->timeout = upcf->timeout;
  769. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  770. "trackuploads error-tracking adding: %08XD", node->key);
  771. }
  772. finish:
  773. /* call the filter chain as usual */
  774. return ngx_http_next_header_filter(r);
  775. }
  776. static ngx_int_t
  777. ngx_http_uploadprogress_init(ngx_conf_t * cf)
  778. {
  779. ngx_http_handler_pt *h;
  780. ngx_http_core_main_conf_t *cmcf;
  781. cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
  782. /* install the tracking handler */
  783. h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
  784. if (h == NULL) {
  785. return NGX_ERROR;
  786. }
  787. *h = ngx_http_uploadprogress_handler;
  788. /*
  789. we also need to track HTTP errors
  790. unfortunately, the above handler is not called in case of
  791. errors.
  792. we have to register a header output filter that will be
  793. called in any case to track those errors
  794. */
  795. ngx_http_next_header_filter = ngx_http_top_header_filter;
  796. ngx_http_top_header_filter = ngx_http_uploadprogress_errortracker;
  797. return NGX_OK;
  798. }
  799. static void*
  800. ngx_http_uploadprogress_create_loc_conf(ngx_conf_t * cf)
  801. {
  802. ngx_http_uploadprogress_conf_t *conf;
  803. conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uploadprogress_conf_t));
  804. if (conf == NULL) {
  805. return NGX_CONF_ERROR;
  806. }
  807. return conf;
  808. }
  809. static char*
  810. ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t * cf, void *parent, void *child)
  811. {
  812. ngx_http_uploadprogress_conf_t *prev = parent;
  813. ngx_http_uploadprogress_conf_t *conf = child;
  814. if (conf->shm_zone == NULL) {
  815. *conf = *prev;
  816. }
  817. return NGX_CONF_OK;
  818. }
  819. static char*
  820. ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
  821. {
  822. ssize_t n;
  823. ngx_str_t *value;
  824. ngx_shm_zone_t *shm_zone;
  825. ngx_http_uploadprogress_ctx_t *ctx;
  826. value = cf->args->elts;
  827. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  828. "ngx_upload_progress name: %V", &value[1]);
  829. ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_uploadprogress_ctx_t));
  830. if (ctx == NULL) {
  831. return NGX_CONF_ERROR;
  832. }
  833. ctx->list_head.prev = NULL;
  834. ctx->list_head.next = &ctx->list_tail;
  835. ctx->list_tail.prev = &ctx->list_head;
  836. ctx->list_tail.next = NULL;
  837. n = ngx_parse_size(&value[2]);
  838. if (n == NGX_ERROR) {
  839. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  840. "invalid size of track_uploads \"%V\"", &value[2]);
  841. return NGX_CONF_ERROR;
  842. }
  843. if (n < (ngx_int_t) (8 * ngx_pagesize)) {
  844. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  845. "track_uploads \"%V\" is too small", &value[1]);
  846. return NGX_CONF_ERROR;
  847. }
  848. shm_zone = ngx_shared_memory_add(cf, &value[1], n,
  849. &ngx_http_uploadprogress_module);
  850. if (shm_zone == NULL) {
  851. return NGX_CONF_ERROR;
  852. }
  853. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  854. "ngx_upload_progress name: %V, szhm_zone: %p", &value[1],
  855. shm_zone);
  856. if (shm_zone->data) {
  857. ctx = shm_zone->data;
  858. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  859. "track_uploads \"%V\" is already created", &value[1]);
  860. return NGX_CONF_ERROR;
  861. }
  862. shm_zone->init = ngx_http_uploadprogress_init_zone;
  863. shm_zone->data = ctx;
  864. return NGX_CONF_OK;
  865. }
  866. static char*
  867. ngx_http_track_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
  868. {
  869. ngx_http_core_loc_conf_t *clcf;
  870. ngx_http_uploadprogress_conf_t *lzcf = conf;
  871. ngx_str_t *value;
  872. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_track_uploads in");
  873. value = cf->args->elts;
  874. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  875. "ngx_track_uploads name: %V", &value[1]);
  876. lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
  877. &ngx_http_uploadprogress_module);
  878. if (lzcf->shm_zone == NULL) {
  879. return NGX_CONF_ERROR;
  880. }
  881. lzcf->track = (u_char) 1;
  882. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  883. "ngx_track_uploads name: %V,szhm_zone: %p", &value[1],
  884. lzcf->shm_zone);
  885. lzcf->timeout = ngx_parse_time(&value[2], 1);
  886. if (lzcf->timeout == NGX_ERROR) {
  887. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  888. "track_uploads \"%V\" timeout value invalid", &value[1]);
  889. return NGX_CONF_ERROR;
  890. }
  891. if (lzcf->timeout == NGX_PARSE_LARGE_TIME) {
  892. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  893. "track_uploads \"%V\" timeout value must be less than 68 years", &value[1]);
  894. return NGX_CONF_ERROR;
  895. }
  896. clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  897. lzcf->handler = clcf->handler;
  898. if ( lzcf->handler == NULL )
  899. {
  900. return "track_upload should be the last directive in the location, after either proxy_pass or fastcgi_pass";
  901. }
  902. clcf->handler = ngx_http_uploadprogress_content_handler;
  903. return NGX_CONF_OK;
  904. }
  905. static char*
  906. ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
  907. {
  908. ngx_http_uploadprogress_conf_t *lzcf = conf;
  909. ngx_http_core_loc_conf_t *clcf;
  910. ngx_str_t *value;
  911. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_report_uploads in");
  912. value = cf->args->elts;
  913. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  914. "ngx_report_uploads name: %V", &value[1]);
  915. lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
  916. &ngx_http_uploadprogress_module);
  917. if (lzcf->shm_zone == NULL) {
  918. return NGX_CONF_ERROR;
  919. }
  920. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  921. "ngx_report_uploads name: %V, szhm_zone: %p", &value[1],
  922. lzcf->shm_zone);
  923. lzcf->track = (u_char) 0;
  924. /* install our report handler */
  925. clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  926. clcf->handler = ngx_http_reportuploads_handler;
  927. return NGX_CONF_OK;
  928. }