You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2013/06/26 22:25:47 UTC
svn commit: r1497079 - in /tomcat/jk/trunk/native/common: jk_ajp_common.c
jk_lb_worker.c jk_service.h
Author: rjung
Date: Wed Jun 26 20:25:47 2013
New Revision: 1497079
URL: http://svn.apache.org/r1497079
Log:
Add ability to set additional response headers
which do not come from the backend.
Use them to set a cookie if "set_session_cookie"
is true and we didn't get a session cookie, or
couldn't fulfil the routing condition required.
Documentation next.
Modified:
tomcat/jk/trunk/native/common/jk_ajp_common.c
tomcat/jk/trunk/native/common/jk_lb_worker.c
tomcat/jk/trunk/native/common/jk_service.h
Modified: tomcat/jk/trunk/native/common/jk_ajp_common.c
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_ajp_common.c?rev=1497079&r1=1497078&r2=1497079&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_ajp_common.c (original)
+++ tomcat/jk/trunk/native/common/jk_ajp_common.c Wed Jun 26 20:25:47 2013
@@ -1870,6 +1870,32 @@ static int ajp_process_callback(jk_msg_b
JK_TRACE_EXIT(l);
return JK_AJP13_ERROR;
}
+ if (r->num_resp_headers > 0) {
+ char **old_names = res.header_names;
+ char **old_values = res.header_values;
+ if (JK_IS_DEBUG_LEVEL(l))
+ jk_log(l, JK_LOG_DEBUG, "Adding %d response headers to %d headers received from tomcat", r->num_resp_headers, res.num_headers);
+ res.header_names = jk_pool_alloc(r->pool,
+ (r->num_resp_headers + res.num_headers) * sizeof(char *));
+ res.header_values = jk_pool_alloc(r->pool,
+ (r->num_resp_headers + res.num_headers) * sizeof(char *));
+ if (!res.header_names || !res.header_values) {
+ jk_log(l, JK_LOG_ERROR,
+ "Failed allocating one %d response headers.", r->num_resp_headers + res.num_headers);
+ res.header_names = old_names;
+ res.header_values = old_values;
+ } else {
+ if (res.num_headers) {
+ memcpy(res.header_names, old_names, res.num_headers * sizeof(char *));
+ memcpy(res.header_values, old_values, res.num_headers * sizeof(char *));
+ }
+ if (r->num_resp_headers) {
+ memcpy(res.header_names + res.num_headers, r->resp_headers_names, r->num_resp_headers * sizeof(char *));
+ memcpy(res.header_values + res.num_headers, r->resp_headers_values, r->num_resp_headers * sizeof(char *));
+ }
+ res.num_headers = res.num_headers + r->num_resp_headers;
+ }
+ }
r->http_response_status = res.status;
if (r->extension.fail_on_status_size > 0)
rc = is_http_status_fail(r->extension.fail_on_status_size,
Modified: tomcat/jk/trunk/native/common/jk_lb_worker.c
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_lb_worker.c?rev=1497079&r1=1497078&r2=1497079&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_lb_worker.c (original)
+++ tomcat/jk/trunk/native/common/jk_lb_worker.c Wed Jun 26 20:25:47 2013
@@ -1307,6 +1307,41 @@ static int JK_METHOD service(jk_endpoint
if (p->worker->lblock == JK_LB_LOCK_PESSIMISTIC)
jk_shm_unlock();
+ if (!s->sticky && (s->extension.set_session_cookie || p->worker->set_session_cookie)) {
+ char **old_names = s->resp_headers_names;
+ char **old_values = s->resp_headers_values;
+ s->resp_headers_names = jk_pool_alloc(s->pool,
+ (s->num_resp_headers + 1) * sizeof(char *));
+ s->resp_headers_values = jk_pool_alloc(s->pool,
+ (s->num_resp_headers + 1) * sizeof(char *));
+ if (!s->resp_headers_names || !s->resp_headers_values) {
+ jk_log(l, JK_LOG_ERROR,
+ "Failed allocating %d new response headers.", s->num_resp_headers + 1);
+ s->resp_headers_names = old_names;
+ s->resp_headers_values = old_values;
+ } else if (s->num_resp_headers) {
+ memcpy(s->resp_headers_names, old_names, s->num_resp_headers * sizeof(char *));
+ memcpy(s->resp_headers_values, old_values, s->num_resp_headers * sizeof(char *));
+ }
+ s->resp_headers_names[s->num_resp_headers] = "Set-Cookie";
+ s->resp_headers_values[s->num_resp_headers] = jk_pool_strcatv(s->pool, p->worker->session_cookie,
+ "=.", rec->route,
+ NULL);
+ if (p->worker->session_cookie_path && *p->worker->session_cookie_path) {
+ s->resp_headers_values[s->num_resp_headers] = jk_pool_strcatv(s->pool, s->resp_headers_values[s->num_resp_headers],
+ ";PATH=", p->worker->session_cookie_path,
+ NULL);
+ }
+ s->resp_headers_values[s->num_resp_headers] = jk_pool_strcatv(s->pool, s->resp_headers_values[s->num_resp_headers],
+ ";HttpOnly",
+ (s->is_ssl ? ";Secure" : ""),
+ NULL);
+ if (JK_IS_DEBUG_LEVEL(l))
+ jk_log(l, JK_LOG_DEBUG, "Added cookie header '%s' with value '%s' ",
+ s->resp_headers_names[s->num_resp_headers],
+ s->resp_headers_values[s->num_resp_headers]);
+ s->num_resp_headers++;
+ }
service_stat = end->service(end, s, l, &is_service_error);
rd = end->rd;
wr = end->wr;
Modified: tomcat/jk/trunk/native/common/jk_service.h
URL: http://svn.apache.org/viewvc/tomcat/jk/trunk/native/common/jk_service.h?rev=1497079&r1=1497078&r2=1497079&view=diff
==============================================================================
--- tomcat/jk/trunk/native/common/jk_service.h (original)
+++ tomcat/jk/trunk/native/common/jk_service.h Wed Jun 26 20:25:47 2013
@@ -208,7 +208,6 @@ struct jk_ws_service
char **headers_values; /* Values of the request headers */
unsigned num_headers; /* Number of request headers */
-
/*
* Request attributes.
*
@@ -224,6 +223,16 @@ struct jk_ws_service
unsigned num_attributes; /* Number of request attributes */
/*
+ * Response headers, names and values.
+ * These are additional headers that we want to add to
+ * the headers send to us from tomcat.
+ * Example: a stickyness cookie header
+ */
+ char **resp_headers_names; /* Names of the response headers */
+ char **resp_headers_values; /* Values of the response headers */
+ unsigned num_resp_headers; /* Number of response headers */
+
+ /*
* JK_TRUE iff handled by a load balancer, the request
* contained a route and it is the route of the current worker.
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org