@@ -99,11 +99,17 @@ static char *ngx_http_track_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *
9999static char * ngx_http_report_uploads (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
100100static char * ngx_http_upload_progress (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
101101static char * ngx_http_upload_progress_template (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
102- static char * ngx_http_upload_progress_java_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
103- static char * ngx_http_upload_progress_json_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
104- static char * ngx_http_upload_progress_jsonp_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
105- static char * ngx_http_upload_progress_json_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
106- static char * ngx_http_upload_progress_jsonp_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
102+
103+ static char * ngx_http_upload_progress_output_internal (
104+ ngx_conf_t * cf , ngx_command_t * cmd , void * conf , ngx_uint_t multi ,
105+ ngx_str_t content_type , ngx_str_t * templates
106+ );
107+ static char * ngx_http_upload_progress_java_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
108+ static char * ngx_http_upload_progress_json_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
109+ static char * ngx_http_upload_progress_jsonp_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
110+ static char * ngx_http_upload_progress_json_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
111+ static char * ngx_http_upload_progress_jsonp_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf );
112+
107113static void ngx_clean_old_connections (ngx_event_t * ev );
108114static ngx_int_t ngx_http_uploadprogress_content_handler (ngx_http_request_t * r );
109115
@@ -1831,133 +1837,74 @@ ngx_http_upload_progress_template(ngx_conf_t * cf, ngx_command_t * cmd, void *co
18311837}
18321838
18331839static char *
1834- ngx_http_upload_progress_java_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1835- {
1840+ ngx_http_upload_progress_output_internal (
1841+ ngx_conf_t * cf , ngx_command_t * cmd , void * conf , ngx_uint_t multi ,
1842+ ngx_str_t content_type , ngx_str_t * templates
1843+ ) {
18361844 ngx_http_uploadprogress_conf_t * upcf = conf ;
18371845 ngx_http_uploadprogress_template_t * t ;
18381846 ngx_uint_t i ;
18391847 char * rc ;
18401848
1841- upcf -> json_multiple = 0 ;
1849+ upcf -> json_multiple = multi ;
18421850
18431851 t = (ngx_http_uploadprogress_template_t * )upcf -> templates .elts ;
18441852
18451853 for (i = 0 ; i < upcf -> templates .nelts ; i ++ ) {
1846- rc = ngx_http_upload_progress_set_template (
1847- cf , t + i , ngx_http_uploadprogress_java_defaults + i );
1848-
1854+ rc = ngx_http_upload_progress_set_template (cf , t + i , templates + i );
18491855 if (rc != NGX_CONF_OK ) {
18501856 return rc ;
18511857 }
18521858 }
18531859
1854- upcf -> content_type = ( ngx_str_t ) ngx_string ( "text/javascript" ) ;
1860+ upcf -> content_type = content_type ;
18551861
18561862 return NGX_CONF_OK ;
18571863}
18581864
18591865static char *
1860- ngx_http_upload_progress_json_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1866+ ngx_http_upload_progress_java_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
18611867{
1862- ngx_http_uploadprogress_conf_t * upcf = conf ;
1863- ngx_http_uploadprogress_template_t * t ;
1864- ngx_uint_t i ;
1865- char * rc ;
1866-
1867- upcf -> json_multiple = 0 ;
1868-
1869- t = (ngx_http_uploadprogress_template_t * )upcf -> templates .elts ;
1870-
1871- for (i = 0 ; i < upcf -> templates .nelts ; i ++ ) {
1872- rc = ngx_http_upload_progress_set_template (
1873- cf , t + i , ngx_http_uploadprogress_json_defaults + i );
1874-
1875- if (rc != NGX_CONF_OK ) {
1876- return rc ;
1877- }
1878- }
1879-
1880- upcf -> content_type = (ngx_str_t )ngx_string ("application/json" );
1881-
1882- return NGX_CONF_OK ;
1868+ return ngx_http_upload_progress_output_internal (
1869+ cf , cmd , conf , 0 ,
1870+ (ngx_str_t )ngx_string ("text/javascript" ),
1871+ ngx_http_uploadprogress_java_defaults );
18831872}
18841873
18851874static char *
1886- ngx_http_upload_progress_jsonp_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1875+ ngx_http_upload_progress_json_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
18871876{
1888- ngx_http_uploadprogress_conf_t * upcf = conf ;
1889- ngx_http_uploadprogress_template_t * t ;
1890- ngx_uint_t i ;
1891- char * rc ;
1892-
1893- upcf -> json_multiple = 0 ;
1894-
1895- t = (ngx_http_uploadprogress_template_t * )upcf -> templates .elts ;
1896-
1897- for (i = 0 ; i < upcf -> templates .nelts ; i ++ ) {
1898- rc = ngx_http_upload_progress_set_template (
1899- cf , t + i , ngx_http_uploadprogress_jsonp_defaults + i );
1900-
1901- if (rc != NGX_CONF_OK ) {
1902- return rc ;
1903- }
1904- }
1905-
1906- upcf -> content_type = (ngx_str_t )ngx_string ("application/javascript" );
1907-
1908- return NGX_CONF_OK ;
1877+ return ngx_http_upload_progress_output_internal (
1878+ cf , cmd , conf , 0 ,
1879+ (ngx_str_t )ngx_string ("application/json" ),
1880+ ngx_http_uploadprogress_json_defaults );
19091881}
19101882
19111883static char *
1912- ngx_http_upload_progress_json_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1884+ ngx_http_upload_progress_jsonp_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
19131885{
1914- ngx_http_uploadprogress_conf_t * upcf = conf ;
1915- ngx_http_uploadprogress_template_t * t ;
1916- ngx_uint_t i ;
1917- char * rc ;
1918-
1919- upcf -> json_multiple = 1 ;
1920-
1921- t = (ngx_http_uploadprogress_template_t * )upcf -> templates .elts ;
1922-
1923- for (i = 0 ; i < upcf -> templates .nelts ; i ++ ) {
1924- rc = ngx_http_upload_progress_set_template (
1925- cf , t + i , ngx_http_uploadprogress_json_multiple_defaults + i );
1926-
1927- if (rc != NGX_CONF_OK ) {
1928- return rc ;
1929- }
1930- }
1931-
1932- upcf -> content_type = (ngx_str_t )ngx_string ("application/json" );
1933-
1934- return NGX_CONF_OK ;
1886+ return ngx_http_upload_progress_output_internal (
1887+ cf , cmd , conf , 0 ,
1888+ (ngx_str_t )ngx_string ("application/javascript" ),
1889+ ngx_http_uploadprogress_jsonp_defaults );
19351890}
19361891
19371892static char *
1938- ngx_http_upload_progress_jsonp_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1893+ ngx_http_upload_progress_json_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
19391894{
1940- ngx_http_uploadprogress_conf_t * upcf = conf ;
1941- ngx_http_uploadprogress_template_t * t ;
1942- ngx_uint_t i ;
1943- char * rc ;
1944-
1945- upcf -> json_multiple = 1 ;
1946-
1947- t = (ngx_http_uploadprogress_template_t * )upcf -> templates .elts ;
1948-
1949- for (i = 0 ; i < upcf -> templates .nelts ; i ++ ) {
1950- rc = ngx_http_upload_progress_set_template (
1951- cf , t + i , ngx_http_uploadprogress_jsonp_multiple_defaults + i );
1952-
1953- if (rc != NGX_CONF_OK ) {
1954- return rc ;
1955- }
1956- }
1957-
1958- upcf -> content_type = (ngx_str_t )ngx_string ("application/json" );
1895+ return ngx_http_upload_progress_output_internal (
1896+ cf , cmd , conf , 1 ,
1897+ (ngx_str_t )ngx_string ("application/json" ),
1898+ ngx_http_uploadprogress_json_multiple_defaults );
1899+ }
19591900
1960- return NGX_CONF_OK ;
1901+ static char *
1902+ ngx_http_upload_progress_jsonp_multiple_output (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1903+ {
1904+ return ngx_http_upload_progress_output_internal (
1905+ cf , cmd , conf , 1 ,
1906+ (ngx_str_t )ngx_string ("application/json" ),
1907+ ngx_http_uploadprogress_jsonp_multiple_defaults );
19611908}
19621909
19631910static ngx_int_t ngx_http_uploadprogress_received_variable (ngx_http_request_t * r ,
0 commit comments