Ver código fonte

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

tags/v0.9.0
dbuschho 14 anos atrás
pai
commit
b950e60c41
2 arquivos alterados com 35 adições e 3 exclusões
  1. 34
    2
      ngx_http_uploadprogress_module.c
  2. 1
    1
      test/client.sh

+ 34
- 2
ngx_http_uploadprogress_module.c Ver arquivo

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
         
1543
     return ngx_http_upload_progress_set_template(cf, t, &value[2]);
1551
     return ngx_http_upload_progress_set_template(cf, t, &value[2]);
1544
 }
1552
 }
1545
 
1553
 
1554
+static char*
1555
+ngx_http_upload_progress_java_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
1556
+{
1557
+    ngx_http_uploadprogress_conf_t       *upcf = conf;
1558
+    ngx_http_uploadprogress_template_t   *t;
1559
+    ngx_uint_t                            i;
1560
+    char*                                 rc;
1561
+
1562
+    t = (ngx_http_uploadprogress_template_t*)upcf->templates.elts;
1563
+
1564
+    for(i = 0;i < upcf->templates.nelts;i++) {
1565
+        rc = ngx_http_upload_progress_set_template(cf, t + i, ngx_http_uploadprogress_java_defaults + i);
1566
+
1567
+        if(rc != NGX_CONF_OK) {
1568
+            return rc;
1569
+        }
1570
+    }
1571
+
1572
+    upcf->content_type.data = (u_char*)"text/javascript";
1573
+    upcf->content_type.len = sizeof("text/javascript") - 1;
1574
+
1575
+    return NGX_CONF_OK;
1576
+}
1577
+
1546
 static char*
1578
 static char*
1547
 ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
1579
 ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
1548
 {
1580
 {

+ 1
- 1
test/client.sh Ver arquivo

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

Carregando…
Cancelar
Salvar