From 8021cb02de840d6168a98e4eefb9bdfbe51ba96e Mon Sep 17 00:00:00 2001 From: Vladimir Homutov Date: Thu, 8 Jun 2017 15:39:06 +0300 Subject: Sticky: added the "header" parameter in the learn mode. With this parameter set, sessions are learned after receiving upstream headers. --- .../modules/ngx_http_upstream_keepalive_module.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/http/modules/ngx_http_upstream_keepalive_module.c') diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c b/src/http/modules/ngx_http_upstream_keepalive_module.c index 1a4dfd776..8858922a0 100644 --- a/src/http/modules/ngx_http_upstream_keepalive_module.c +++ b/src/http/modules/ngx_http_upstream_keepalive_module.c @@ -52,6 +52,8 @@ typedef struct { ngx_event_save_peer_session_pt original_save_session; #endif + ngx_event_notify_peer_pt original_notify; + } ngx_http_upstream_keepalive_peer_data_t; @@ -73,6 +75,9 @@ static void ngx_http_upstream_keepalive_save_session(ngx_peer_connection_t *pc, void *data); #endif +static void ngx_http_upstream_notify_keepalive_peer(ngx_peer_connection_t *pc, + void *data, ngx_uint_t type); + static void *ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf); static char *ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); @@ -228,6 +233,11 @@ ngx_http_upstream_init_keepalive_peer(ngx_http_request_t *r, r->upstream->peer.save_session = ngx_http_upstream_keepalive_save_session; #endif + if (r->upstream->peer.notify) { + kp->original_notify = r->upstream->peer.notify; + r->upstream->peer.notify = ngx_http_upstream_notify_keepalive_peer; + } + return NGX_OK; } @@ -507,6 +517,16 @@ ngx_http_upstream_keepalive_save_session(ngx_peer_connection_t *pc, void *data) #endif +static void +ngx_http_upstream_notify_keepalive_peer(ngx_peer_connection_t *pc, void *data, + ngx_uint_t type) +{ + ngx_http_upstream_keepalive_peer_data_t *kp = data; + + kp->original_notify(pc, kp->data, type); +} + + static void * ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf) { -- cgit