@@ -37,9 +37,16 @@ char       *ngx_http_fastcgi_cache_purge_conf(ngx_conf_t *cf,
3737                ngx_command_t  * cmd , void  * conf );
3838char        * ngx_http_proxy_cache_purge_conf (ngx_conf_t  * cf ,
3939                ngx_command_t  * cmd , void  * conf );
40+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
41+ char        * ngx_http_uwsgi_cache_purge_conf (ngx_conf_t  * cf ,
42+                 ngx_command_t  * cmd , void  * conf );
43+ #endif 
4044
4145ngx_int_t    ngx_http_fastcgi_cache_purge_handler (ngx_http_request_t  * r );
4246ngx_int_t    ngx_http_proxy_cache_purge_handler (ngx_http_request_t  * r );
47+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
48+ ngx_int_t    ngx_http_uwsgi_cache_purge_handler (ngx_http_request_t  * r );
49+ #endif 
4350
4451ngx_int_t    ngx_http_cache_purge_handler (ngx_http_request_t  * r ,
4552    ngx_http_file_cache_t  * cache , ngx_http_complex_value_t  * cache_key );
@@ -63,6 +70,15 @@ static ngx_command_t  ngx_http_cache_purge_module_commands[] = {
6370      0 ,
6471      NULL  },
6572
73+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
74+     { ngx_string ("uwsgi_cache_purge" ),
75+       NGX_HTTP_LOC_CONF |NGX_CONF_TAKE2 ,
76+       ngx_http_uwsgi_cache_purge_conf ,
77+       NGX_HTTP_LOC_CONF_OFFSET ,
78+       0 ,
79+       NULL  },
80+ #endif 
81+ 
6682      ngx_null_command 
6783};
6884
@@ -111,6 +127,9 @@ CRLF "</center>" CRLF
111127
112128extern  ngx_module_t   ngx_http_fastcgi_module ;
113129extern  ngx_module_t   ngx_http_proxy_module ;
130+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
131+ extern  ngx_module_t   ngx_http_uwsgi_module ;
132+ #endif 
114133
115134/* this is ugly workaround, find better solution... */ 
116135typedef  struct  {
@@ -183,6 +202,30 @@ typedef struct {
183202    ngx_uint_t                      headers_hash_max_size ;
184203    ngx_uint_t                      headers_hash_bucket_size ;
185204} ngx_http_proxy_loc_conf_t ;
205+ 
206+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
207+ typedef  struct  {
208+     ngx_http_upstream_conf_t    upstream ;
209+ 
210+     ngx_array_t                * flushes ;
211+     ngx_array_t                * params_len ;
212+     ngx_array_t                * params ;
213+     ngx_array_t                * params_source ;
214+ 
215+     ngx_hash_t                  headers_hash ;
216+     ngx_uint_t                  header_params ;
217+ 
218+     ngx_array_t                * uwsgi_lengths ;
219+     ngx_array_t                * uwsgi_values ;
220+ 
221+     ngx_http_complex_value_t    cache_key ;
222+ 
223+     ngx_str_t                   uwsgi_string ;
224+ 
225+     ngx_uint_t                  modifier1 ;
226+     ngx_uint_t                  modifier2 ;
227+ } ngx_http_uwsgi_loc_conf_t ;
228+ #endif 
186229/* end of ugly workaround */ 
187230
188231char  * 
@@ -292,6 +335,61 @@ ngx_http_proxy_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
292335    return  NGX_CONF_OK ;
293336}
294337
338+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
339+ char  * 
340+ ngx_http_uwsgi_cache_purge_conf (ngx_conf_t  * cf , ngx_command_t  * cmd , void  * conf )
341+ {
342+     ngx_http_compile_complex_value_t    ccv ;
343+     ngx_http_core_loc_conf_t           * clcf ;
344+     ngx_http_uwsgi_loc_conf_t          * ulcf ;
345+     ngx_str_t                          * value ;
346+ 
347+     ulcf  =  ngx_http_conf_get_module_loc_conf (cf , ngx_http_uwsgi_module );
348+ 
349+     /* check for duplicates / collisions */ 
350+     if  (ulcf -> upstream .cache  !=  NGX_CONF_UNSET_PTR 
351+         &&  ulcf -> upstream .cache  !=  NULL )
352+     {
353+         return  "is either duplicate or collides with \"uwsgi_cache\"" ;
354+     }
355+ 
356+     if  (ulcf -> upstream .upstream  ||  ulcf -> uwsgi_lengths ) {
357+         return  "is incompatible with \"uwsgi_pass\"" ;
358+     }
359+ 
360+     if  (ulcf -> upstream .store  >  0  ||  ulcf -> upstream .store_lengths ) {
361+         return  "is incompatible with \"uwsgi_store\"" ;
362+     }
363+ 
364+     value  =  cf -> args -> elts ;
365+ 
366+     /* set uwsgi_cache part */ 
367+     ulcf -> upstream .cache  =  ngx_shared_memory_add (cf , & value [1 ], 0 ,
368+                                                  & ngx_http_uwsgi_module );
369+     if  (ulcf -> upstream .cache  ==  NULL ) {
370+         return  NGX_CONF_ERROR ;
371+     }
372+ 
373+     /* set uwsgi_cache_key part */ 
374+     ngx_memzero (& ccv , sizeof (ngx_http_compile_complex_value_t ));
375+ 
376+     ccv .cf  =  cf ;
377+     ccv .value  =  & value [2 ];
378+     ccv .complex_value  =  & ulcf -> cache_key ;
379+ 
380+     if  (ngx_http_compile_complex_value (& ccv ) !=  NGX_OK ) {
381+         return  NGX_CONF_ERROR ;
382+     }
383+ 
384+     /* set handler */ 
385+     clcf  =  ngx_http_conf_get_module_loc_conf (cf , ngx_http_core_module );
386+ 
387+     clcf -> handler  =  ngx_http_uwsgi_cache_purge_handler ;
388+ 
389+     return  NGX_CONF_OK ;
390+ }
391+ #endif 
392+ 
295393ngx_int_t 
296394ngx_http_fastcgi_cache_purge_handler (ngx_http_request_t  * r )
297395{
@@ -322,6 +420,23 @@ ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r)
322420                                        & plcf -> cache_key );
323421}
324422
423+ #if  defined(nginx_version ) &&  (nginx_version  >= 8040 )
424+ ngx_int_t 
425+ ngx_http_uwsgi_cache_purge_handler (ngx_http_request_t  * r )
426+ {
427+     ngx_http_uwsgi_loc_conf_t   * ulcf ;
428+ 
429+     if  (!(r -> method  &  (NGX_HTTP_GET |NGX_HTTP_HEAD |NGX_HTTP_DELETE ))) {
430+         return  NGX_HTTP_NOT_ALLOWED ;
431+     }
432+ 
433+     ulcf  =  ngx_http_get_module_loc_conf (r , ngx_http_uwsgi_module );
434+ 
435+     return  ngx_http_cache_purge_handler (r , ulcf -> upstream .cache -> data ,
436+                                         & ulcf -> cache_key );
437+ }
438+ #endif 
439+ 
325440ngx_int_t 
326441ngx_http_cache_purge_handler (ngx_http_request_t  * r ,
327442    ngx_http_file_cache_t  * cache , ngx_http_complex_value_t  * cache_key )
0 commit comments