httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: httpd-2.0/modules/proxy mod_proxy.c mod_proxy.h
Date Wed, 11 Aug 2004 21:56:38 GMT
wrowe       2004/08/11 14:56:38

  Modified:    modules/proxy mod_proxy.c mod_proxy.h
  Log:
  Add pre_request and post_request proxy hooks.
  They will be mainly used for loadbalancers for finding and maintaining workers.
  
  Submitted by: mturk
  
  Revision  Changes    Path
  1.112     +28 -1     httpd-2.0/modules/proxy/mod_proxy.c
  
  Index: mod_proxy.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/proxy/mod_proxy.c,v
  retrieving revision 1.111
  retrieving revision 1.112
  diff -u -r1.111 -r1.112
  --- mod_proxy.c	11 Aug 2004 21:46:54 -0000	1.111
  +++ mod_proxy.c	11 Aug 2004 21:56:37 -0000	1.112
  @@ -473,6 +473,8 @@
       int direct_connect = 0;
       const char *str;
       long maxfwd;
  +    struct proxy_balancer *balancer = NULL;
  +    proxy_worker *worker = NULL;
   
       /* is this for us? */
       if (!r->proxyreq || !r->filename || strncmp(r->filename, "proxy:", 6) != 0)
  @@ -549,7 +551,12 @@
                         r->uri);
   #endif
       }
  -
  +    /* Try to obtain the most suitable worker */
  +    access_status = proxy_run_pre_request(&worker, &balancer, r, conf, &url);
  +    if (access_status != DECLINED && access_status != OK) {
  +        return access_status;
  +    }
  +                                          
       /* firstly, try a proxy, unless a NoProxy directive is active */
       if (!direct_connect) {
           for (i = 0; i < proxies->nelts; i++) {
  @@ -591,6 +598,11 @@
                       "using LoadModule.", r->uri);
           return HTTP_FORBIDDEN;
       }
  +    access_status = proxy_run_post_request(worker, balancer, r, conf);
  +    if (access_status == DECLINED) {
  +        access_status = OK; /* no post_request handler available */
  +        /* TODO: reclycle direct worker */
  +    }
       return access_status;
   }
   
  @@ -1481,6 +1493,8 @@
   APR_HOOK_STRUCT(
   	APR_HOOK_LINK(scheme_handler)
   	APR_HOOK_LINK(canon_handler)
  +	APR_HOOK_LINK(pre_request)
  +	APR_HOOK_LINK(post_request)
   )
   
   APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, scheme_handler, 
  @@ -1491,6 +1505,19 @@
   APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, canon_handler, 
                                        (request_rec *r, char *url),(r,
                                        url),DECLINED)
  +APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, pre_request, (
  +                                      proxy_worker **worker,
  +                                      struct proxy_balancer **balancer,
  +                                      request_rec *r, 
  +                                      proxy_server_conf *conf,
  +                                      char **url),(worker,balancer,
  +                                      r,conf,url),DECLINED)
  +APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(proxy, PROXY, int, post_request,
  +                                      (proxy_worker *worker,
  +                                       struct proxy_balancer *balancer,
  +                                       request_rec *r,
  +                                       proxy_server_conf *conf),(worker,
  +                                       balancer,r,conf),DECLINED)
   APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(proxy, PROXY, int, fixups,
   				    (request_rec *r), (r),
   				    OK, DECLINED)
  
  
  
  1.99      +29 -0     httpd-2.0/modules/proxy/mod_proxy.h
  
  Index: mod_proxy.h
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/proxy/mod_proxy.h,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- mod_proxy.h	11 Aug 2004 21:44:23 -0000	1.98
  +++ mod_proxy.h	11 Aug 2004 21:56:38 -0000	1.99
  @@ -249,6 +249,14 @@
   #endif
   };
   
  +/* data structure for set/get module_config */
  +typedef struct {
  +    char                  *url;         /* rewtitten url */
  +    struct proxy_balancer *balancer;    /* load balancer to use */
  +    proxy_worker          *worker;      /* most suitable worker */
  +    void                  *opaque;      /* module private data */
  +} proxy_module_conf;
  +
   /* hooks */
   
   /* Create a set of PROXY_DECLARE(type), PROXY_DECLARE_NONSTD(type) and 
  @@ -287,6 +295,27 @@
   
   APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, create_req, (request_rec *r, request_rec *pr))
   APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, fixups, (request_rec *r)) 
  +
  +/**
  + * pre request hook.
  + * It will return the most suitable worker at the moment
  + * and coresponding balancer.
  + * The url is rewritten from balancer://cluster/uri to scheme://host:port/uri
  + * and then the scheme_handler is called.
  + *
  + */
  +APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, pre_request, (proxy_worker **worker,
  +                          struct proxy_balancer **balancer,
  +                          request_rec *r,
  +                          proxy_server_conf *conf, char **url))                       
  
  +/**
  + * post request hook.
  + * It is called after request for updating runtime balancer status.
  + */
  +APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, post_request, (proxy_worker *worker,
  +                          struct proxy_balancer *balancer, request_rec *r,
  +                          proxy_server_conf *conf))
  +
   
   /* proxy_util.c */
   
  
  
  

Mime
View raw message