Procházet zdrojové kódy

Changed default upload progress response format to JSONP. Also fixed typo in test/client.sh

pull/17/head
dbuschho před 14 roky
rodič
revize
1afb8a663b
2 změnil soubory, kde provedl 35 přidání a 3 odebrání
  1. 34
    2
      ngx_http_uploadprogress_module.c
  2. 1
    1
      test/client.sh

+ 34
- 2
ngx_http_uploadprogress_module.c Zobrazit soubor

94
 static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
94
 static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
95
 static char *ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
95
 static char *ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
96
 static char* ngx_http_upload_progress_template(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
96
 static char* ngx_http_upload_progress_template(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
97
+static char* ngx_http_upload_progress_java_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
97
 static char* ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
98
 static char* ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
98
 static char* ngx_http_upload_progress_jsonp_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
99
 static char* ngx_http_upload_progress_jsonp_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
99
 static void ngx_clean_old_connections(ngx_event_t * ev);
100
 static void ngx_clean_old_connections(ngx_event_t * ev);
138
      offsetof(ngx_http_uploadprogress_conf_t, templates),
139
      offsetof(ngx_http_uploadprogress_conf_t, templates),
139
      NULL},
140
      NULL},
140
 
141
 
142
+    {ngx_string("upload_progress_java_output"),
143
+     NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_NOARGS,
144
+     ngx_http_upload_progress_java_output,
145
+     NGX_HTTP_LOC_CONF_OFFSET,
146
+     0,
147
+     NULL},
148
+
141
     {ngx_string("upload_progress_json_output"),
149
     {ngx_string("upload_progress_json_output"),
142
      NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_NOARGS,
150
      NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_NOARGS,
143
      ngx_http_upload_progress_json_output,
151
      ngx_http_upload_progress_json_output,
1330
 
1338
 
1331
     while(m->name.data != NULL) {
1339
     while(m->name.data != NULL) {
1332
         ngx_http_uploadprogress_template_t *elt = ngx_array_push(&ngx_http_uploadprogress_global_templates);
1340
         ngx_http_uploadprogress_template_t *elt = ngx_array_push(&ngx_http_uploadprogress_global_templates);
1333
-        ngx_http_script_variables_count(ngx_http_uploadprogress_java_defaults + i);
1341
+        ngx_http_script_variables_count(ngx_http_uploadprogress_jsonp_defaults + i);
1334
 
1342
 
1335
-        if (ngx_http_upload_progress_set_template(cf, elt, ngx_http_uploadprogress_java_defaults + i) != NGX_CONF_OK) {
1343
+        if (ngx_http_upload_progress_set_template(cf, elt, ngx_http_uploadprogress_jsonp_defaults + i) != NGX_CONF_OK) {
1336
             return NGX_ERROR;
1344
             return NGX_ERROR;
1337
         }
1345
         }
1338
         
1346
         
1549
     return ngx_http_upload_progress_set_template(cf, t, &value[2]);
1557
     return ngx_http_upload_progress_set_template(cf, t, &value[2]);
1550
 }
1558
 }
1551
 
1559
 
1560
+static char*
1561
+ngx_http_upload_progress_java_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
1562
+{
1563
+    ngx_http_uploadprogress_conf_t       *upcf = conf;
1564
+    ngx_http_uploadprogress_template_t   *t;
1565
+    ngx_uint_t                            i;
1566
+    char*                                 rc;
1567
+
1568
+    t = (ngx_http_uploadprogress_template_t*)upcf->templates.elts;
1569
+
1570
+    for(i = 0;i < upcf->templates.nelts;i++) {
1571
+        rc = ngx_http_upload_progress_set_template(cf, t + i, ngx_http_uploadprogress_java_defaults + i);
1572
+
1573
+        if(rc != NGX_CONF_OK) {
1574
+            return rc;
1575
+        }
1576
+    }
1577
+
1578
+    upcf->content_type.data = (u_char*)"text/javascript";
1579
+    upcf->content_type.len = sizeof("text/javascript") - 1;
1580
+
1581
+    return NGX_CONF_OK;
1582
+}
1583
+
1552
 static char*
1584
 static char*
1553
 ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
1585
 ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
1554
 {
1586
 {

+ 1
- 1
test/client.sh Zobrazit soubor

1
 #!/bin/sh
1
 #!/bin/sh
2
-# usqge: client.sh UPLOAD_ID PROGRESS_URL
2
+# usage: client.sh UPLOAD_ID PROGRESS_URL
3
 cont=""
3
 cont=""
4
 while [ "$cont" != "new Object({ 'state' : 'done' })" ]
4
 while [ "$cont" != "new Object({ 'state' : 'done' })" ]
5
 do
5
 do

Načítá se…
Zrušit
Uložit