Skip to content

Commit b950e60

Browse files
dbuschhoBrice Figureau
authored andcommitted
Changed default upload progress response format to JSONP. Also fixed typo in test/client.sh
1 parent 82b35fc commit b950e60

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

ngx_http_uploadprogress_module.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static char *ngx_http_track_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *
9494
static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
9595
static char *ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
9696
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);
9798
static char* ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
9899
static char* ngx_http_upload_progress_jsonp_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
99100
static void ngx_clean_old_connections(ngx_event_t * ev);
@@ -138,6 +139,13 @@ static ngx_command_t ngx_http_uploadprogress_commands[] = {
138139
offsetof(ngx_http_uploadprogress_conf_t, templates),
139140
NULL},
140141

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+
141149
{ngx_string("upload_progress_json_output"),
142150
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF | NGX_CONF_NOARGS,
143151
ngx_http_upload_progress_json_output,
@@ -1330,9 +1338,9 @@ ngx_http_uploadprogress_init_variables_and_templates(ngx_conf_t *cf)
13301338

13311339
while(m->name.data != NULL) {
13321340
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);
13341342

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) {
13361344
return NGX_ERROR;
13371345
}
13381346

@@ -1543,6 +1551,30 @@ ngx_http_upload_progress_template(ngx_conf_t * cf, ngx_command_t * cmd, void *co
15431551
return ngx_http_upload_progress_set_template(cf, t, &value[2]);
15441552
}
15451553

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+
15461578
static char*
15471579
ngx_http_upload_progress_json_output(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
15481580
{

test/client.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
2-
# usqge: client.sh UPLOAD_ID PROGRESS_URL
2+
# usage: client.sh UPLOAD_ID PROGRESS_URL
33
cont=""
44
while [ "$cont" != "new Object({ 'state' : 'done' })" ]
55
do

0 commit comments

Comments
 (0)