Sfoglia il codice sorgente

fixed ugly up conf that was storing the read_event_handler - instead store it in the http request context

tags/v0.4
Brice Figureau 18 anni fa
parent
commit
b9c2b4bc6d
1 ha cambiato i file con 27 aggiunte e 15 eliminazioni
  1. 27
    15
      ngx_http_uploadprogress_module.c

+ 27
- 15
ngx_http_uploadprogress_module.c Vedi File

@@ -42,10 +42,13 @@ typedef struct {
42 42
     time_t                           timeout;
43 43
     ngx_event_t                      cleanup;
44 44
     ngx_http_handler_pt              handler;
45
-    ngx_http_event_handler_pt        read_event_handler;
46 45
     u_char                           track;
47 46
 } ngx_http_uploadprogress_conf_t;
48 47
 
48
+typedef struct {
49
+    ngx_http_event_handler_pt        read_event_handler;
50
+} ngx_http_uploadprogress_module_ctx_t;
51
+
49 52
 static ngx_int_t ngx_http_reportuploads_handler(ngx_http_request_t *r);
50 53
 static void ngx_http_uploadprogress_cleanup(void *data);
51 54
 static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
@@ -257,8 +260,10 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r);
257 260
 static ngx_int_t
258 261
 ngx_http_uploadprogress_content_handler(ngx_http_request_t *r)
259 262
 {
260
-    ngx_int_t                        rc;
261
-    ngx_http_uploadprogress_conf_t  *upcf;
263
+    ngx_int_t                                    rc;
264
+    ngx_http_uploadprogress_module_ctx_t        *ctx;
265
+    ngx_http_uploadprogress_conf_t              *upcf;
266
+    
262 267
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_content_handler");
263 268
     upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
264 269
 
@@ -270,27 +275,33 @@ ngx_http_uploadprogress_content_handler(ngx_http_request_t *r)
270 275
       return rc;
271 276
     
272 277
     /* request is OK, hijack the read_event_handler */
273
-    upcf->read_event_handler = r->read_event_handler;
278
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uploadprogress_module_ctx_t));
279
+    if (ctx == NULL) {
280
+      return NGX_ERROR;
281
+    }
282
+
283
+    ngx_http_set_ctx(r, ctx, ngx_http_uploadprogress_module);
274 284
     r->read_event_handler = ngx_http_uploadprogress_event_handler;
275 285
     return rc;
276 286
 }
277 287
 
278 288
 static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
279 289
 {
280
-    ngx_str_t                       *id;
281
-    ngx_slab_pool_t                 *shpool;
282
-    ngx_connection_t                *c;
283
-    ngx_http_uploadprogress_ctx_t   *ctx;
284
-    ngx_http_uploadprogress_node_t  *up;
285
-    ngx_http_uploadprogress_conf_t  *upcf;
290
+    ngx_str_t                                   *id;
291
+    ngx_slab_pool_t                             *shpool;
292
+    ngx_connection_t                            *c;
293
+    ngx_http_uploadprogress_ctx_t               *ctx;
294
+    ngx_http_uploadprogress_node_t              *up;
295
+    ngx_http_uploadprogress_conf_t              *upcf;
296
+    ngx_http_uploadprogress_module_ctx_t        *module_ctx;
286 297
 
287 298
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
288 299
     
289 300
     c = r->connection;
290 301
     
291 302
     /* call the original read event handler */
292
-    upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
293
-    upcf->read_event_handler(r);
303
+    module_ctx = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
304
+    module_ctx->read_event_handler(r);
294 305
 
295 306
     /* check that the request/connection is still OK */
296 307
     if (r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE) {
@@ -309,6 +320,7 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
309 320
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
310 321
                    "upload-progress: read_event_handler found id: %V", id);
311 322
 
323
+    upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
312 324
     if (upcf->shm_zone == NULL) {
313 325
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
314 326
                        "upload-progress: read_event_handler no shm_zone for id: %V", id);
@@ -326,8 +338,8 @@ static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
326 338
     if (up != NULL && !up->done) {
327 339
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
328 340
                        "upload-progress: read_event_handler found node: %V", id);
329
-				up->rest = r->request_body->rest;
330
-				up->length = r->headers_in.content_length_n;
341
+        up->rest = r->request_body->rest;
342
+        up->length = r->headers_in.content_length_n;
331 343
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
332 344
                        "upload-progress: read_event_handler storing rest %uO/%uO for %V", up->rest, up->length, id);
333 345
     } else {
@@ -344,7 +356,7 @@ ngx_http_reportuploads_handler(ngx_http_request_t * r)
344 356
     ngx_str_t                       *id;
345 357
     ngx_buf_t                       *b;
346 358
     ngx_chain_t                      out;
347
-		ngx_int_t                        rc, size, found=0, done=0, err_status=0;
359
+    ngx_int_t                        rc, size, found=0, done=0, err_status=0;
348 360
     off_t                            rest=0, length=0;
349 361
     ngx_uint_t                       len, i;
350 362
     ngx_slab_pool_t                 *shpool;

Loading…
Annulla
Salva