MEDIUM: stream: move the frontend's pointer to the session

Just like for the listener, the frontend is session-wide so let's move
it to the session. There are a lot of places which were changed but the
changes are minimal in fact.
diff --git a/src/backend.c b/src/backend.c
index d56d46f..921dad0 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1090,7 +1090,7 @@
 	}
 
 	/* flag for logging source ip/port */
-	if (s->fe->options2 & PR_O2_SRC_ADDR)
+	if (strm_sess(s)->fe->options2 & PR_O2_SRC_ADDR)
 		s->si[1].flags |= SI_FL_SRC_ADDR;
 
 	/* disable lingering */
diff --git a/src/compression.c b/src/compression.c
index feade6b..0ae634f 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -36,6 +36,7 @@
 #include <proto/compression.h>
 #include <proto/freq_ctr.h>
 #include <proto/proto_http.h>
+#include <proto/stream.h>
 
 
 #ifdef USE_ZLIB
@@ -318,10 +319,10 @@
 	/* update input rate */
 	if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) {
 		update_freq_ctr(&global.comp_bps_in, msg->next);
-		s->fe->fe_counters.comp_in += msg->next;
+		strm_sess(s)->fe->fe_counters.comp_in += msg->next;
 		s->be->be_counters.comp_in += msg->next;
 	} else {
-		s->fe->fe_counters.comp_byp += msg->next;
+		strm_sess(s)->fe->fe_counters.comp_byp += msg->next;
 		s->be->be_counters.comp_byp += msg->next;
 	}
 
@@ -345,7 +346,7 @@
 
 	if (s->comp_ctx && s->comp_ctx->cur_lvl > 0) {
 		update_freq_ctr(&global.comp_bps_out, to_forward);
-		s->fe->fe_counters.comp_out += to_forward;
+		strm_sess(s)->fe->fe_counters.comp_out += to_forward;
 		s->be->be_counters.comp_out += to_forward;
 	}
 
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 47a009d..1562078 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -1511,8 +1511,8 @@
 						resume_listener(l);
 				}
 
-				if (px->maxconn > px->feconn && !LIST_ISEMPTY(&s->fe->listener_queue))
-					dequeue_all_listeners(&s->fe->listener_queue);
+				if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_sess(s)->fe->listener_queue))
+					dequeue_all_listeners(&strm_sess(s)->fe->listener_queue);
 
 				return 1;
 			}
@@ -5044,7 +5044,7 @@
 
 		chunk_appendf(&trash,
 			     "  frontend=%s (id=%u mode=%s), listener=%s (id=%u)",
-			     sess->fe->id, sess->fe->uuid, sess->fe->mode ? "http" : "tcp",
+			     strm_sess(sess)->fe->id, strm_sess(sess)->fe->uuid, strm_sess(sess)->fe->mode ? "http" : "tcp",
 			     strm_sess(sess)->listener ? strm_sess(sess)->listener->name ? strm_sess(sess)->listener->name : "?" : "?",
 			     strm_sess(sess)->listener ? strm_sess(sess)->listener->luid : 0);
 
@@ -5612,7 +5612,7 @@
 					     " src=%s:%d fe=%s be=%s srv=%s",
 					     pn,
 					     get_host_port(&conn->addr.from),
-					     curr_sess->fe->id,
+					     strm_sess(curr_sess)->fe->id,
 					     (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
 					     objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
 					     );
@@ -5621,7 +5621,7 @@
 				chunk_appendf(&trash,
 					     " src=unix:%d fe=%s be=%s srv=%s",
 					     strm_sess(curr_sess)->listener->luid,
-					     curr_sess->fe->id,
+					     strm_sess(curr_sess)->fe->id,
 					     (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>",
 					     objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>"
 					     );
diff --git a/src/frontend.c b/src/frontend.c
index a64ff4f..1b3abfa 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -54,8 +54,10 @@
  */
 int frontend_accept(struct stream *s)
 {
+	struct session *sess = s->sess;
 	struct connection *conn = __objt_conn(s->si[0].end);
-	struct listener *l = strm_sess(s)->listener;
+	struct listener *l = sess->listener;
+	struct proxy *fe = sess->fe;
 
 	int cfd = conn->t.sock.fd;
 
@@ -82,11 +84,11 @@
 			       (char *) &one, sizeof(one)) == -1)
 			goto out_return;
 
-		if (s->fe->options & PR_O_TCP_CLI_KA)
+		if (fe->options & PR_O_TCP_CLI_KA)
 			setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE,
 				   (char *) &one, sizeof(one));
 
-		if (s->fe->options & PR_O_TCP_NOLING)
+		if (fe->options & PR_O_TCP_NOLING)
 			fdtab[cfd].linger_risk = 1;
 
 #if defined(TCP_MAXSEG)
@@ -108,19 +110,19 @@
 	if (global.tune.client_rcvbuf)
 		setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &global.tune.client_rcvbuf, sizeof(global.tune.client_rcvbuf));
 
-	if (unlikely(s->fe->nb_req_cap > 0)) {
-		if ((s->txn.req.cap = pool_alloc2(s->fe->req_cap_pool)) == NULL)
+	if (unlikely(fe->nb_req_cap > 0)) {
+		if ((s->txn.req.cap = pool_alloc2(fe->req_cap_pool)) == NULL)
 			goto out_return;	/* no memory */
-		memset(s->txn.req.cap, 0, s->fe->nb_req_cap * sizeof(void *));
+		memset(s->txn.req.cap, 0, fe->nb_req_cap * sizeof(void *));
 	}
 
-	if (unlikely(s->fe->nb_rsp_cap > 0)) {
-		if ((s->txn.rsp.cap = pool_alloc2(s->fe->rsp_cap_pool)) == NULL)
+	if (unlikely(fe->nb_rsp_cap > 0)) {
+		if ((s->txn.rsp.cap = pool_alloc2(fe->rsp_cap_pool)) == NULL)
 			goto out_free_reqcap;	/* no memory */
-		memset(s->txn.rsp.cap, 0, s->fe->nb_rsp_cap * sizeof(void *));
+		memset(s->txn.rsp.cap, 0, fe->nb_rsp_cap * sizeof(void *));
 	}
 
-	if (s->fe->http_needed) {
+	if (fe->http_needed) {
 		/* we have to allocate header indexes only if we know
 		 * that we may make use of them. This of course includes
 		 * (mode == PR_MODE_HTTP).
@@ -134,9 +136,9 @@
 		http_init_txn(s);
 	}
 
-	if ((s->fe->mode == PR_MODE_TCP || s->fe->mode == PR_MODE_HTTP)
-	    && (!LIST_ISEMPTY(&s->fe->logsrvs))) {
-		if (likely(!LIST_ISEMPTY(&s->fe->logformat))) {
+	if ((fe->mode == PR_MODE_TCP || fe->mode == PR_MODE_HTTP)
+	    && (!LIST_ISEMPTY(&fe->logsrvs))) {
+		if (likely(!LIST_ISEMPTY(&fe->logformat))) {
 			/* we have the client ip */
 			if (s->logs.logwait & LW_CLIP)
 				if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT)))
@@ -152,16 +154,16 @@
 			case AF_INET:
 			case AF_INET6:
 				addr_to_str(&conn->addr.to, sn, sizeof(sn));
-				send_log(s->fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
+				send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
 					 pn, get_host_port(&conn->addr.from),
 					 sn, get_host_port(&conn->addr.to),
-					 s->fe->id, (s->fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
+					 fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
 				break;
 			case AF_UNIX:
 				/* UNIX socket, only the destination is known */
-				send_log(s->fe, LOG_INFO, "Connect to unix:%d (%s/%s)\n",
+				send_log(fe, LOG_INFO, "Connect to unix:%d (%s/%s)\n",
 					 l->luid,
-					 s->fe->id, (s->fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
+					 fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
 				break;
 			}
 		}
@@ -176,13 +178,13 @@
 		case AF_INET:
 		case AF_INET6:
 			chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n",
-			             s->uniq_id, s->fe->id, (unsigned short)l->fd, (unsigned short)cfd,
+			             s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)cfd,
 			             pn, get_host_port(&conn->addr.from));
 			break;
 		case AF_UNIX:
 			/* UNIX socket, only the destination is known */
 			chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [unix:%d]\n",
-			             s->uniq_id, s->fe->id, (unsigned short)l->fd, (unsigned short)cfd,
+			             s->uniq_id, fe->id, (unsigned short)l->fd, (unsigned short)cfd,
 			             l->luid);
 			break;
 		}
@@ -190,7 +192,7 @@
 		shut_your_big_mouth_gcc(write(1, trash.str, trash.len));
 	}
 
-	if (s->fe->mode == PR_MODE_HTTP)
+	if (fe->mode == PR_MODE_HTTP)
 		s->req.flags |= CF_READ_DONTWAIT; /* one read is usually enough */
 
 	/* note: this should not happen anymore since there's always at least the switching rules */
@@ -199,17 +201,17 @@
 		channel_auto_close(&s->req);    /* let the producer forward close requests */
 	}
 
-	s->req.rto = s->fe->timeout.client;
-	s->res.wto = s->fe->timeout.client;
+	s->req.rto = fe->timeout.client;
+	s->res.wto = fe->timeout.client;
 
 	/* everything's OK, let's go on */
 	return 1;
 
 	/* Error unrolling */
  out_free_rspcap:
-	pool_free2(s->fe->rsp_cap_pool, s->txn.rsp.cap);
+	pool_free2(fe->rsp_cap_pool, s->txn.rsp.cap);
  out_free_reqcap:
-	pool_free2(s->fe->req_cap_pool, s->txn.req.cap);
+	pool_free2(fe->req_cap_pool, s->txn.req.cap);
  out_return:
 	return -1;
 }
@@ -225,7 +227,7 @@
 {
 	smp->flags = SMP_F_VOL_SESS;
 	smp->type = SMP_T_UINT;
-	smp->data.uint = l4->fe->uuid;
+	smp->data.uint = strm_sess(l4)->fe->uuid;
 	return 1;
 }
 
diff --git a/src/hlua.c b/src/hlua.c
index 1a0b920..2934054 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2139,8 +2139,8 @@
 	socket->s->flags = 0;
 
 	/* Assign the configured proxy to the new stream. */
+	socket->s->sess->fe = &socket_proxy;
 	socket->s->be = &socket_proxy;
-	socket->s->fe = &socket_proxy;
 
 	/* XXX: Set namy variables */
 	socket->s->store_count = 0;
diff --git a/src/log.c b/src/log.c
index d2ae535..80ac989 100644
--- a/src/log.c
+++ b/src/log.c
@@ -920,7 +920,7 @@
 int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list_format)
 {
 	struct session *sess = strm_sess(s);
-	struct proxy *fe = s->fe;
+	struct proxy *fe = sess->fe;
 	struct proxy *be = s->be;
 	struct http_txn *txn = &s->txn;
 	char *uri;
@@ -1541,13 +1541,13 @@
 
 			case LOG_FMT_LOGCNT: // %lc
 				if (tmp->options & LOG_OPT_HEXA) {
-					iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", s->fe->log_count);
+					iret = snprintf(tmplog, dst + maxsize - tmplog, "%04X", fe->log_count);
 					if (iret < 0 || iret > dst + maxsize - tmplog)
 						goto out;
 					last_isspace = 0;
 					tmplog += iret;
 				} else {
-					ret = ultoa_o(s->fe->log_count, tmplog, dst + maxsize - tmplog);
+					ret = ultoa_o(fe->log_count, tmplog, dst + maxsize - tmplog);
 					if (ret == NULL)
 						goto out;
 					tmplog = ret;
@@ -1606,6 +1606,7 @@
  */
 void strm_log(struct stream *s)
 {
+	struct session *sess = s->sess;
 	char *tmplog;
 	int size, err, level;
 
@@ -1614,12 +1615,12 @@
               ((s->flags & SF_ERR_MASK) > SF_ERR_LOCAL) ||
 	      (((s->flags & SF_ERR_MASK) == SF_ERR_NONE) &&
 	       (s->si[1].conn_retries != s->be->conn_retries)) ||
-	      ((s->fe->mode == PR_MODE_HTTP) && s->txn.status >= 500);
+	      ((sess->fe->mode == PR_MODE_HTTP) && s->txn.status >= 500);
 
-	if (!err && (s->fe->options2 & PR_O2_NOLOGNORM))
+	if (!err && (sess->fe->options2 & PR_O2_NOLOGNORM))
 		return;
 
-	if (LIST_ISEMPTY(&s->fe->logsrvs))
+	if (LIST_ISEMPTY(&sess->fe->logsrvs))
 		return;
 
 	if (s->logs.level) { /* loglevel was overridden */
@@ -1631,22 +1632,22 @@
 	}
 	else {
 		level = LOG_INFO;
-		if (err && (s->fe->options2 & PR_O2_LOGERRORS))
+		if (err && (sess->fe->options2 & PR_O2_LOGERRORS))
 			level = LOG_ERR;
 	}
 
 	/* if unique-id was not generated */
-	if (!s->unique_id && !LIST_ISEMPTY(&s->fe->format_unique_id)) {
+	if (!s->unique_id && !LIST_ISEMPTY(&sess->fe->format_unique_id)) {
 		if ((s->unique_id = pool_alloc2(pool2_uniqueid)) != NULL)
-			build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
+			build_logline(s, s->unique_id, UNIQUEID_LEN, &sess->fe->format_unique_id);
 	}
 
-	tmplog = update_log_hdr(s->fe->log_tag ? s->fe->log_tag : global.log_tag);
+	tmplog = update_log_hdr(sess->fe->log_tag ? sess->fe->log_tag : global.log_tag);
 	size = tmplog - logline;
-	size += build_logline(s, tmplog, global.max_syslog_len - size, &s->fe->logformat);
+	size += build_logline(s, tmplog, global.max_syslog_len - size, &sess->fe->logformat);
 	if (size > 0) {
-		s->fe->log_count++;
-		__send_log(s->fe, level, logline, size + 1);
+		sess->fe->log_count++;
+		__send_log(sess->fe, level, logline, size + 1);
 		s->logs.logwait = 0;
 	}
 }
diff --git a/src/peers.c b/src/peers.c
index 98ce8bf..df6d47a 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -215,7 +215,7 @@
 static void peer_io_handler(struct stream_interface *si)
 {
 	struct stream *s = si_strm(si);
-	struct peers *curpeers = (struct peers *)s->fe->parent;
+	struct peers *curpeers = (struct peers *)strm_sess(s)->fe->parent;
 	struct appctx *appctx = objt_appctx(si->end);
 	int reql = 0;
 	int repl = 0;
@@ -1151,12 +1151,8 @@
 	}
 
 	s->sess->listener = l;
-
-	/* Note: initially, the stream's backend points to the frontend.
-	 * This changes later when switching rules are executed or
-	 * when the default backend is assigned.
-	 */
-	s->be = s->fe = p;
+	s->sess->fe = p;
+	s->be = s->sess->fe;
 	s->req.buf = s->res.buf = NULL;
 
 	s->si[0].flags = SI_FL_NONE;
@@ -1165,7 +1161,7 @@
 	si_reset(&s->si[0]);
 	si_set_state(&s->si[0], SI_ST_EST);
 
-	if (s->fe->options2 & PR_O2_INDEPSTR)
+	if (s->sess->fe->options2 & PR_O2_INDEPSTR)
 		s->si[0].flags |= SI_FL_INDEP_STR;
 
 	appctx = stream_int_register_handler(&s->si[0], &peer_applet);
@@ -1245,14 +1241,14 @@
 		channel_auto_close(&s->req);/* let the producer forward close requests */
 	}
 
-	s->req.rto = s->fe->timeout.client;
+	s->req.rto = s->sess->fe->timeout.client;
 	s->req.wto = s->be->timeout.server;
 
 	channel_init(&s->res);
 	s->res.flags |= CF_ISRESP;
 
 	s->res.rto = s->be->timeout.server;
-	s->res.wto = s->fe->timeout.client;
+	s->res.wto = s->sess->fe->timeout.client;
 
 	s->req.rex = TICK_ETERNITY;
 	s->req.wex = TICK_ETERNITY;
diff --git a/src/proto_http.c b/src/proto_http.c
index 4af1b80..0c7bbc4 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -850,8 +850,8 @@
 {
 	if (s->be->errmsg[msgnum].str)
 		return &s->be->errmsg[msgnum];
-	else if (s->fe->errmsg[msgnum].str)
-		return &s->fe->errmsg[msgnum];
+	else if (strm_sess(s)->fe->errmsg[msgnum].str)
+		return &strm_sess(s)->fe->errmsg[msgnum];
 	else
 		return &http_err_chunks[msgnum];
 }
@@ -2262,7 +2262,7 @@
 	}
 
 	/* search for the algo in the backend in priority or the frontend */
-	if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || (s->fe->comp && (comp_algo_back = s->fe->comp->algos))) {
+	if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || (strm_sess(s)->fe->comp && (comp_algo_back = strm_sess(s)->fe->comp->algos))) {
 		int best_q = 0;
 
 		ctx.idx = 0;
@@ -2320,7 +2320,7 @@
 
 	/* remove all occurrences of the header when "compression offload" is set */
 	if (s->comp_algo) {
-		if ((s->be->comp && s->be->comp->offload) || (s->fe->comp && s->fe->comp->offload)) {
+		if ((s->be->comp && s->be->comp->offload) || (strm_sess(s)->fe->comp && strm_sess(s)->fe->comp->offload)) {
 			http_remove_header2(msg, &txn->hdr_idx, &ctx);
 			ctx.idx = 0;
 			while (http_find_header2("Accept-Encoding", 15, req->p, &txn->hdr_idx, &ctx)) {
@@ -2331,7 +2331,7 @@
 	}
 
 	/* identity is implicit does not require headers */
-	if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || (s->fe->comp && (comp_algo_back = s->fe->comp->algos))) {
+	if ((s->be->comp && (comp_algo_back = s->be->comp->algos)) || (strm_sess(s)->fe->comp && (comp_algo_back = strm_sess(s)->fe->comp->algos))) {
 		for (comp_algo = comp_algo_back; comp_algo; comp_algo = comp_algo->next) {
 			if (comp_algo->cfg_name_len == 8 && memcmp(comp_algo->cfg_name, "identity", 8) == 0) {
 				s->comp_algo = comp_algo;
@@ -2398,7 +2398,7 @@
 			goto fail;
 
 		if ((s->be->comp && (comp_type = s->be->comp->types)) ||
-		    (s->fe->comp && (comp_type = s->fe->comp->types))) {
+		    (strm_sess(s)->fe->comp && (comp_type = strm_sess(s)->fe->comp->types))) {
 			for (; comp_type; comp_type = comp_type->next) {
 				if (ctx.vlen >= comp_type->name_len &&
 				    strncasecmp(ctx.line+ctx.val, comp_type->name, comp_type->name_len) == 0)
@@ -2411,7 +2411,7 @@
 		}
 	}
 	else { /* no content-type header */
-		if ((s->be->comp && s->be->comp->types) || (s->fe->comp && s->fe->comp->types))
+		if ((s->be->comp && s->be->comp->types) || (strm_sess(s)->fe->comp && strm_sess(s)->fe->comp->types))
 			goto fail; /* a content-type was required */
 	}
 
@@ -2462,29 +2462,30 @@
 
 void http_adjust_conn_mode(struct stream *s, struct http_txn *txn, struct http_msg *msg)
 {
+	struct proxy *fe = strm_sess(s)->fe;
 	int tmp = TX_CON_WANT_KAL;
 
-	if (!((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)) {
-		if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN ||
+	if (!((fe->options2|s->be->options2) & PR_O2_FAKE_KA)) {
+		if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN ||
 		    (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_TUN)
 			tmp = TX_CON_WANT_TUN;
 
-		if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+		if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 		    (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
 			tmp = TX_CON_WANT_TUN;
 	}
 
-	if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
+	if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL ||
 	    (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_SCL) {
 		/* option httpclose + server_close => forceclose */
-		if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+		if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 		    (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)
 			tmp = TX_CON_WANT_CLO;
 		else
 			tmp = TX_CON_WANT_SCL;
 	}
 
-	if ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL ||
+	if ((fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL ||
 	    (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_FCL)
 		tmp = TX_CON_WANT_CLO;
 
@@ -2497,7 +2498,7 @@
 		int to_del = 0;
 		if ((msg->flags & HTTP_MSGF_VER_11) ||
 		    ((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL &&
-		     !((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)))
+		     !((fe->options2|s->be->options2) & PR_O2_FAKE_KA)))
 			to_del |= 2; /* remove "keep-alive" */
 		if (!(msg->flags & HTTP_MSGF_VER_11))
 			to_del |= 1; /* remove "close" */
@@ -2510,7 +2511,7 @@
 	    ((txn->flags & TX_HDR_CONN_CLO) ||                         /* "connection: close" */
 	     (!(msg->flags & HTTP_MSGF_VER_11) && !(txn->flags & TX_HDR_CONN_KAL)) || /* no "connection: k-a" in 1.0 */
 	     !(msg->flags & HTTP_MSGF_XFER_LEN) ||                     /* no length known => close */
-	     s->fe->state == PR_STSTOPPED))                            /* frontend is stopping */
+	     fe->state == PR_STSTOPPED))                            /* frontend is stopping */
 		txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | TX_CON_WANT_CLO;
 }
 
@@ -2660,7 +2661,7 @@
 		if (unlikely(msg->msg_state == HTTP_MSG_ERROR)) {
 			stream_inc_http_req_ctr(s);
 			stream_inc_http_err_ctr(s);
-			proxy_inc_fe_req_ctr(s->fe);
+			proxy_inc_fe_req_ctr(sess->fe);
 			goto return_bad_req;
 		}
 
@@ -2675,7 +2676,7 @@
 			 */
 			stream_inc_http_req_ctr(s);
 			stream_inc_http_err_ctr(s);
-			proxy_inc_fe_req_ctr(s->fe);
+			proxy_inc_fe_req_ctr(sess->fe);
 			if (msg->err_pos < 0)
 				msg->err_pos = req->buf->i;
 			goto return_bad_req;
@@ -2691,7 +2692,7 @@
 
 			/* we cannot return any message on error */
 			if (msg->err_pos >= 0) {
-				http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 				stream_inc_http_err_ctr(s);
 			}
 
@@ -2701,8 +2702,8 @@
 			req->analysers = 0;
 
 			stream_inc_http_req_ctr(s);
-			proxy_inc_fe_req_ctr(s->fe);
-			s->fe->fe_counters.failed_req++;
+			proxy_inc_fe_req_ctr(sess->fe);
+			sess->fe->fe_counters.failed_req++;
 			if (sess->listener->counters)
 				sess->listener->counters->failed_req++;
 
@@ -2721,7 +2722,7 @@
 
 			/* read timeout : give up with an error message. */
 			if (msg->err_pos >= 0) {
-				http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 				stream_inc_http_err_ctr(s);
 			}
 			txn->status = 408;
@@ -2730,8 +2731,8 @@
 			req->analysers = 0;
 
 			stream_inc_http_req_ctr(s);
-			proxy_inc_fe_req_ctr(s->fe);
-			s->fe->fe_counters.failed_req++;
+			proxy_inc_fe_req_ctr(sess->fe);
+			sess->fe->fe_counters.failed_req++;
 			if (sess->listener->counters)
 				sess->listener->counters->failed_req++;
 
@@ -2749,7 +2750,7 @@
 				goto failed_keep_alive;
 
 			if (msg->err_pos >= 0)
-				http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 			txn->status = 400;
 			stream_int_retnclose(&s->si[0], http_error_message(s, HTTP_ERR_400));
 			msg->msg_state = HTTP_MSG_ERROR;
@@ -2757,8 +2758,8 @@
 
 			stream_inc_http_err_ctr(s);
 			stream_inc_http_req_ctr(s);
-			proxy_inc_fe_req_ctr(s->fe);
-			s->fe->fe_counters.failed_req++;
+			proxy_inc_fe_req_ctr(sess->fe);
+			sess->fe->fe_counters.failed_req++;
 			if (sess->listener->counters)
 				sess->listener->counters->failed_req++;
 
@@ -2828,7 +2829,7 @@
 	 */
 
 	stream_inc_http_req_ctr(s);
-	proxy_inc_fe_req_ctr(s->fe); /* one more valid request for this FE */
+	proxy_inc_fe_req_ctr(sess->fe); /* one more valid request for this FE */
 
 	if (txn->flags & TX_WAIT_NEXT_RQ) {
 		/* kill the pending keep-alive timeout */
@@ -2841,7 +2842,7 @@
 	 * to block on that, so we have to capture it now.
 	 */
 	if (unlikely(msg->err_pos >= 0))
-		http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+		http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 
 	/*
 	 * 1: identify the method
@@ -2857,22 +2858,22 @@
 	 * We have to do this for every request which gets in, because
 	 * the monitor-uri is defined by the frontend.
 	 */
-	if (unlikely((s->fe->monitor_uri_len != 0) &&
-		     (s->fe->monitor_uri_len == msg->sl.rq.u_l) &&
+	if (unlikely((sess->fe->monitor_uri_len != 0) &&
+		     (sess->fe->monitor_uri_len == msg->sl.rq.u_l) &&
 		     !memcmp(req->buf->p + msg->sl.rq.u,
-			     s->fe->monitor_uri,
-			     s->fe->monitor_uri_len))) {
+			     sess->fe->monitor_uri,
+			     sess->fe->monitor_uri_len))) {
 		/*
 		 * We have found the monitor URI
 		 */
 		struct acl_cond *cond;
 
 		s->flags |= SF_MONITOR;
-		s->fe->fe_counters.intercepted_req++;
+		sess->fe->fe_counters.intercepted_req++;
 
 		/* Check if we want to fail this monitor request or not */
-		list_for_each_entry(cond, &s->fe->mon_fail_cond, list) {
-			int ret = acl_exec_cond(cond, s->fe, s, txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+		list_for_each_entry(cond, &sess->fe->mon_fail_cond, list) {
+			int ret = acl_exec_cond(cond, sess->fe, s, txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 
 			ret = acl_pass(ret);
 			if (cond->pol == ACL_COND_UNLESS)
@@ -2941,7 +2942,7 @@
 	 * a proxied connection, which covers both "scheme://location" and
 	 * CONNECT ip:port.
 	 */
-	if ((s->fe->options2 & PR_O2_USE_PXHDR) &&
+	if ((sess->fe->options2 & PR_O2_USE_PXHDR) &&
 	    req->buf->p[msg->sl.rq.u] != '/' && req->buf->p[msg->sl.rq.u] != '*')
 		txn->flags |= TX_USE_PX_CONN;
 
@@ -2951,7 +2952,7 @@
 	/* 5: we may need to capture headers */
 	if (unlikely((s->logs.logwait & LW_REQHDR) && txn->req.cap))
 		capture_headers(req->buf->p, &txn->hdr_idx,
-				txn->req.cap, s->fe->req_cap);
+				txn->req.cap, sess->fe->req_cap);
 
 	/* 6: determine the transfer-length.
 	 * According to RFC2616 #4.4, amended by the HTTPbis working group,
@@ -3050,7 +3051,7 @@
 	 * time.
 	 */
 	if (!(txn->flags & TX_HDR_CONN_PRS) ||
-	    ((s->fe->options & PR_O_HTTP_MODE) != (s->be->options & PR_O_HTTP_MODE)))
+	    ((sess->fe->options & PR_O_HTTP_MODE) != (s->be->options & PR_O_HTTP_MODE)))
 		http_adjust_conn_mode(s, txn, msg);
 
 	/* end of job, return OK */
@@ -3064,14 +3065,14 @@
 		/* we detected a parsing error. We want to archive this request
 		 * in the dedicated proxy area for later troubleshooting.
 		 */
-		http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+		http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 	}
 
 	txn->req.msg_state = HTTP_MSG_ERROR;
 	txn->status = 400;
 	stream_int_retnclose(&s->si[0], http_error_message(s, HTTP_ERR_400));
 
-	s->fe->fe_counters.failed_req++;
+	sess->fe->fe_counters.failed_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->failed_req++;
 
@@ -3576,7 +3577,7 @@
 						                       t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u, 1);
 
 					stkctr_set_flags(&s->stkctr[http_req_trk_idx(rule->action)], STKCTR_TRACK_CONTENT);
-					if (s->fe != s->be)
+					if (strm_sess(s)->fe != s->be)
 						stkctr_set_flags(&s->stkctr[http_req_trk_idx(rule->action)], STKCTR_TRACK_BACKEND);
 				}
 			}
@@ -4179,8 +4180,8 @@
 	/* Proceed with the stats now. */
 	if (unlikely(objt_applet(s->target) == &http_stats_applet)) {
 		/* process the stats request now */
-		if (s->fe == s->be) /* report it if the request was intercepted by the frontend */
-			s->fe->fe_counters.intercepted_req++;
+		if (sess->fe == s->be) /* report it if the request was intercepted by the frontend */
+			sess->fe->fe_counters.intercepted_req++;
 
 		if (!(s->flags & SF_ERR_MASK))      // this is not really an error but it is
 			s->flags |= SF_ERR_LOCAL;   // to mark that it comes from the proxy
@@ -4188,7 +4189,7 @@
 			s->flags |= SF_FINST_R;
 
 		/* we may want to compress the stats page */
-		if (s->fe->comp || s->be->comp)
+		if (sess->fe->comp || s->be->comp)
 			select_compression_request_header(s, req->buf);
 
 		/* enable the minimally required analyzers to handle keep-alive and compression on the HTTP response */
@@ -4248,8 +4249,8 @@
 	if (!req->analyse_exp)
 		req->analyse_exp = tick_add(now_ms, 0);
 	stream_inc_http_err_ctr(s);
-	s->fe->fe_counters.denied_req++;
-	if (s->fe != s->be)
+	sess->fe->fe_counters.denied_req++;
+	if (sess->fe != s->be)
 		s->be->be_counters.denied_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->denied_req++;
@@ -4261,8 +4262,8 @@
 	s->logs.tv_request = now;
 	stream_int_retnclose(&s->si[0], http_error_message(s, HTTP_ERR_403));
 	stream_inc_http_err_ctr(s);
-	s->fe->fe_counters.denied_req++;
-	if (s->fe != s->be)
+	sess->fe->fe_counters.denied_req++;
+	if (sess->fe != s->be)
 		s->be->be_counters.denied_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->denied_req++;
@@ -4274,14 +4275,14 @@
 		/* we detected a parsing error. We want to archive this request
 		 * in the dedicated proxy area for later troubleshooting.
 		 */
-		http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+		http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 	}
 
 	txn->req.msg_state = HTTP_MSG_ERROR;
 	txn->status = 400;
 	stream_int_retnclose(&s->si[0], http_error_message(s, HTTP_ERR_400));
 
-	s->fe->fe_counters.failed_req++;
+	sess->fe->fe_counters.failed_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->failed_req++;
 
@@ -4327,7 +4328,7 @@
 		req->buf->i,
 		req->analysers);
 
-	if (s->fe->comp || s->be->comp)
+	if (sess->fe->comp || s->be->comp)
 		select_compression_request_header(s, req->buf);
 
 	/*
@@ -4401,7 +4402,7 @@
 	 * the fields will stay coherent and the URI will not move.
 	 * This should only be performed in the backend.
 	 */
-	if ((s->be->cookie_name || s->be->appsession_name || s->fe->capture_name)
+	if ((s->be->cookie_name || s->be->appsession_name || sess->fe->capture_name)
 	    && !(txn->flags & (TX_CLDENY|TX_CLTARPIT)))
 		manage_client_side_cookies(s, req);
 
@@ -4417,15 +4418,15 @@
 
 	/* add unique-id if "header-unique-id" is specified */
 
-	if (!LIST_ISEMPTY(&s->fe->format_unique_id)) {
+	if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
 		if ((s->unique_id = pool_alloc2(pool2_uniqueid)) == NULL)
 			goto return_bad_req;
 		s->unique_id[0] = '\0';
-		build_logline(s, s->unique_id, UNIQUEID_LEN, &s->fe->format_unique_id);
+		build_logline(s, s->unique_id, UNIQUEID_LEN, &sess->fe->format_unique_id);
 	}
 
-	if (s->fe->header_unique_id && s->unique_id) {
-		chunk_printf(&trash, "%s: %s", s->fe->header_unique_id, s->unique_id);
+	if (sess->fe->header_unique_id && s->unique_id) {
+		chunk_printf(&trash, "%s: %s", sess->fe->header_unique_id, s->unique_id);
 		if (trash.len < 0)
 			goto return_bad_req;
 		if (unlikely(http_header_add_tail2(&txn->req, &txn->hdr_idx, trash.str, trash.len) < 0))
@@ -4436,11 +4437,11 @@
 	 * 9: add X-Forwarded-For if either the frontend or the backend
 	 * asks for it.
 	 */
-	if ((s->fe->options | s->be->options) & PR_O_FWDFOR) {
+	if ((sess->fe->options | s->be->options) & PR_O_FWDFOR) {
 		struct hdr_ctx ctx = { .idx = 0 };
-		if (!((s->fe->options | s->be->options) & PR_O_FF_ALWAYS) &&
-			http_find_header2(s->be->fwdfor_hdr_len ? s->be->fwdfor_hdr_name : s->fe->fwdfor_hdr_name,
-			                  s->be->fwdfor_hdr_len ? s->be->fwdfor_hdr_len : s->fe->fwdfor_hdr_len,
+		if (!((sess->fe->options | s->be->options) & PR_O_FF_ALWAYS) &&
+			http_find_header2(s->be->fwdfor_hdr_len ? s->be->fwdfor_hdr_name : sess->fe->fwdfor_hdr_name,
+			                  s->be->fwdfor_hdr_len ? s->be->fwdfor_hdr_len : sess->fe->fwdfor_hdr_len,
 			                  req->buf->p, &txn->hdr_idx, &ctx)) {
 			/* The header is set to be added only if none is present
 			 * and we found it, so don't do anything.
@@ -4450,9 +4451,9 @@
 			/* Add an X-Forwarded-For header unless the source IP is
 			 * in the 'except' network range.
 			 */
-			if ((!s->fe->except_mask.s_addr ||
-			     (((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr & s->fe->except_mask.s_addr)
-			     != s->fe->except_net.s_addr) &&
+			if ((!sess->fe->except_mask.s_addr ||
+			     (((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr & sess->fe->except_mask.s_addr)
+			     != sess->fe->except_net.s_addr) &&
 			    (!s->be->except_mask.s_addr ||
 			     (((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr & s->be->except_mask.s_addr)
 			     != s->be->except_net.s_addr)) {
@@ -4469,8 +4470,8 @@
 					len = s->be->fwdfor_hdr_len;
 					memcpy(trash.str, s->be->fwdfor_hdr_name, len);
 				} else {
-					len = s->fe->fwdfor_hdr_len;
-					memcpy(trash.str, s->fe->fwdfor_hdr_name, len);
+					len = sess->fe->fwdfor_hdr_len;
+					memcpy(trash.str, sess->fe->fwdfor_hdr_name, len);
 				}
 				len += snprintf(trash.str + len, trash.size - len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
 
@@ -4497,8 +4498,8 @@
 				len = s->be->fwdfor_hdr_len;
 				memcpy(trash.str, s->be->fwdfor_hdr_name, len);
 			} else {
-				len = s->fe->fwdfor_hdr_len;
-				memcpy(trash.str, s->fe->fwdfor_hdr_name, len);
+				len = sess->fe->fwdfor_hdr_len;
+				memcpy(trash.str, sess->fe->fwdfor_hdr_name, len);
 			}
 			len += snprintf(trash.str + len, trash.size - len, ": %s", pn);
 
@@ -4511,7 +4512,7 @@
 	 * 10: add X-Original-To if either the frontend or the backend
 	 * asks for it.
 	 */
-	if ((s->fe->options | s->be->options) & PR_O_ORGTO) {
+	if ((sess->fe->options | s->be->options) & PR_O_ORGTO) {
 
 		/* FIXME: don't know if IPv6 can handle that case too. */
 		if (cli_conn && cli_conn->addr.from.ss_family == AF_INET) {
@@ -4521,9 +4522,9 @@
 			conn_get_to_addr(cli_conn);
 
 			if (cli_conn->addr.to.ss_family == AF_INET &&
-			    ((!s->fe->except_mask_to.s_addr ||
-			      (((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr.s_addr & s->fe->except_mask_to.s_addr)
-			      != s->fe->except_to.s_addr) &&
+			    ((!sess->fe->except_mask_to.s_addr ||
+			      (((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr.s_addr & sess->fe->except_mask_to.s_addr)
+			      != sess->fe->except_to.s_addr) &&
 			     (!s->be->except_mask_to.s_addr ||
 			      (((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr.s_addr & s->be->except_mask_to.s_addr)
 			      != s->be->except_to.s_addr))) {
@@ -4540,8 +4541,8 @@
 					len = s->be->orgto_hdr_len;
 					memcpy(trash.str, s->be->orgto_hdr_name, len);
 				} else {
-					len = s->fe->orgto_hdr_len;
-					memcpy(trash.str, s->fe->orgto_hdr_name, len);
+					len = sess->fe->orgto_hdr_len;
+					memcpy(trash.str, sess->fe->orgto_hdr_name, len);
 				}
 				len += snprintf(trash.str + len, trash.size - len, ": %d.%d.%d.%d", pn[0], pn[1], pn[2], pn[3]);
 
@@ -4558,21 +4559,21 @@
 	 */
 	if (!(txn->flags & TX_HDR_CONN_UPG) &&
 	    (((txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) ||
-	     ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+	     ((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 	      (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL))) {
 		unsigned int want_flags = 0;
 
 		if (msg->flags & HTTP_MSGF_VER_11) {
 			if (((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL ||
-			     ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+			     ((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 			      (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL)) &&
-			    !((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
+			    !((sess->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
 				want_flags |= TX_CON_CLO_SET;
 		} else {
 			if (((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL &&
-			     ((s->fe->options & PR_O_HTTP_MODE) != PR_O_HTTP_PCL &&
+			     ((sess->fe->options & PR_O_HTTP_MODE) != PR_O_HTTP_PCL &&
 			      (s->be->options & PR_O_HTTP_MODE) != PR_O_HTTP_PCL)) ||
-			    ((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
+			    ((sess->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
 				want_flags |= TX_CON_KAL_SET;
 		}
 
@@ -4630,7 +4631,7 @@
 		/* we detected a parsing error. We want to archive this request
 		 * in the dedicated proxy area for later troubleshooting.
 		 */
-		http_capture_bad_message(&s->fe->invalid_req, s, msg, msg->msg_state, s->fe);
+		http_capture_bad_message(&sess->fe->invalid_req, s, msg, msg->msg_state, sess->fe);
 	}
 
 	txn->req.msg_state = HTTP_MSG_ERROR;
@@ -4638,7 +4639,7 @@
 	req->analysers = 0;
 	stream_int_retnclose(&s->si[0], http_error_message(s, HTTP_ERR_400));
 
-	s->fe->fe_counters.failed_req++;
+	sess->fe->fe_counters.failed_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->failed_req++;
 
@@ -4831,7 +4832,7 @@
 
  return_err_msg:
 	req->analysers = 0;
-	s->fe->fe_counters.failed_req++;
+	sess->fe->fe_counters.failed_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->failed_req++;
 	return 0;
@@ -4898,6 +4899,7 @@
 void http_end_txn_clean_session(struct stream *s)
 {
 	int prev_status = s->txn.status;
+	struct proxy *fe = strm_sess(s)->fe;
 
 	/* FIXME: We need a more portable way of releasing a backend's and a
 	 * server's connections. We need a safer way to reinitialize buffer
@@ -4931,10 +4933,10 @@
 		if (n < 1 || n > 5)
 			n = 0;
 
-		if (s->fe->mode == PR_MODE_HTTP) {
-			s->fe->fe_counters.p.http.rsp[n]++;
+		if (fe->mode == PR_MODE_HTTP) {
+			fe->fe_counters.p.http.rsp[n]++;
 			if (s->comp_algo && (s->flags & SF_COMP_READY))
-				s->fe->fe_counters.p.http.comp_rsp++;
+				fe->fe_counters.p.http.comp_rsp++;
 		}
 		if ((s->flags & SF_BE_ASSIGNED) &&
 		    (s->be->mode == PR_MODE_HTTP)) {
@@ -4950,9 +4952,9 @@
 	s->logs.bytes_out -= s->res.buf->i;
 
 	/* let's do a final log if we need it */
-	if (!LIST_ISEMPTY(&s->fe->logformat) && s->logs.logwait &&
+	if (!LIST_ISEMPTY(&fe->logformat) && s->logs.logwait &&
 	    !(s->flags & SF_MONITOR) &&
-	    (!(s->fe->options & PR_O_NULLNOLOG) || s->req.total)) {
+	    (!(fe->options & PR_O_NULLNOLOG) || s->req.total)) {
 		s->do_log(s);
 	}
 
@@ -5021,10 +5023,10 @@
 		s->txn.flags |= TX_PREFER_LAST;
 	}
 
-	if (s->fe->options2 & PR_O2_INDEPSTR)
+	if (fe->options2 & PR_O2_INDEPSTR)
 		s->si[1].flags |= SI_FL_INDEP_STR;
 
-	if (s->fe->options2 & PR_O2_NODELAY) {
+	if (fe->options2 & PR_O2_NODELAY) {
 		s->req.flags |= CF_NEVER_WAIT;
 		s->res.flags |= CF_NEVER_WAIT;
 	}
@@ -5505,7 +5507,7 @@
 			else if (ret < 0) {
 				stream_inc_http_err_ctr(s);
 				if (msg->err_pos >= 0)
-					http_capture_bad_message(&s->fe->invalid_req, s, msg, HTTP_MSG_CHUNK_SIZE, s->be);
+					http_capture_bad_message(&sess->fe->invalid_req, s, msg, HTTP_MSG_CHUNK_SIZE, s->be);
 				goto return_bad_req;
 			}
 			/* otherwise we're in HTTP_MSG_DATA or HTTP_MSG_TRAILERS state */
@@ -5519,7 +5521,7 @@
 			else if (ret < 0) {
 				stream_inc_http_err_ctr(s);
 				if (msg->err_pos >= 0)
-					http_capture_bad_message(&s->fe->invalid_req, s, msg, HTTP_MSG_CHUNK_CRLF, s->be);
+					http_capture_bad_message(&sess->fe->invalid_req, s, msg, HTTP_MSG_CHUNK_CRLF, s->be);
 				goto return_bad_req;
 			}
 			/* we're in MSG_CHUNK_SIZE now */
@@ -5532,7 +5534,7 @@
 			else if (ret < 0) {
 				stream_inc_http_err_ctr(s);
 				if (msg->err_pos >= 0)
-					http_capture_bad_message(&s->fe->invalid_req, s, msg, HTTP_MSG_TRAILERS, s->be);
+					http_capture_bad_message(&sess->fe->invalid_req, s, msg, HTTP_MSG_TRAILERS, s->be);
 				goto return_bad_req;
 			}
 			/* we're in HTTP_MSG_DONE now */
@@ -5566,7 +5568,7 @@
 						goto aborted_xfer;
 					}
 					if (msg->err_pos >= 0)
-						http_capture_bad_message(&s->fe->invalid_req, s, msg, old_state, s->be);
+						http_capture_bad_message(&sess->fe->invalid_req, s, msg, old_state, s->be);
 					goto return_bad_req;
 				}
 				return 1;
@@ -5615,7 +5617,7 @@
 				s->flags |= SF_FINST_D;
 		}
 
-		s->fe->fe_counters.cli_aborts++;
+		sess->fe->fe_counters.cli_aborts++;
 		s->be->be_counters.cli_aborts++;
 		if (objt_server(s->target))
 			objt_server(s->target)->counters.cli_aborts++;
@@ -5647,7 +5649,7 @@
 	return 0;
 
  return_bad_req: /* let's centralize all bad requests */
-	s->fe->fe_counters.failed_req++;
+	sess->fe->fe_counters.failed_req++;
 	if (sess->listener->counters)
 		sess->listener->counters->failed_req++;
 
@@ -5689,7 +5691,7 @@
 	req->analysers = 0;
 	s->res.analysers = 0; /* we're in data phase, we want to abort both directions */
 
-	s->fe->fe_counters.srv_aborts++;
+	sess->fe->fe_counters.srv_aborts++;
 	s->be->be_counters.srv_aborts++;
 	if (objt_server(s->target))
 		objt_server(s->target)->counters.srv_aborts++;
@@ -5714,6 +5716,7 @@
  */
 int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
 {
+	struct session *sess = s->sess;
 	struct http_txn *txn = &s->txn;
 	struct http_msg *msg = &txn->rsp;
 	struct hdr_ctx ctx;
@@ -5813,7 +5816,7 @@
 			 */
 		hdr_response_bad:
 			if (msg->msg_state == HTTP_MSG_ERROR || msg->err_pos >= 0)
-				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, sess->fe);
 
 			s->be->be_counters.failed_resp++;
 			if (objt_server(s->target)) {
@@ -5846,7 +5849,7 @@
 		/* read error */
 		else if (rep->flags & CF_READ_ERROR) {
 			if (msg->err_pos >= 0)
-				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, sess->fe);
 			else if (txn->flags & TX_NOT_FIRST)
 				goto abort_keep_alive;
 
@@ -5873,7 +5876,7 @@
 		/* read timeout : return a 504 to the client. */
 		else if (rep->flags & CF_READ_TIMEOUT) {
 			if (msg->err_pos >= 0)
-				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, sess->fe);
 			else if (txn->flags & TX_NOT_FIRST)
 				goto abort_keep_alive;
 
@@ -5899,7 +5902,7 @@
 
 		/* client abort with an abortonclose */
 		else if ((rep->flags & CF_SHUTR) && ((s->req.flags & (CF_SHUTR|CF_SHUTW)) == (CF_SHUTR|CF_SHUTW))) {
-			s->fe->fe_counters.cli_aborts++;
+			sess->fe->fe_counters.cli_aborts++;
 			s->be->be_counters.cli_aborts++;
 			if (objt_server(s->target))
 				objt_server(s->target)->counters.cli_aborts++;
@@ -5923,7 +5926,7 @@
 		/* close from server, capture the response if the server has started to respond */
 		else if (rep->flags & CF_SHUTR) {
 			if (msg->msg_state >= HTTP_MSG_RPVER || msg->err_pos >= 0)
-				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, sess->fe);
 			else if (txn->flags & TX_NOT_FIRST)
 				goto abort_keep_alive;
 
@@ -5950,7 +5953,7 @@
 		/* write error to client (we don't send any message then) */
 		else if (rep->flags & CF_WRITE_ERROR) {
 			if (msg->err_pos >= 0)
-				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
+				http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, sess->fe);
 			else if (txn->flags & TX_NOT_FIRST)
 				goto abort_keep_alive;
 
@@ -5978,7 +5981,7 @@
 	 */
 
 	if (unlikely(msg->err_pos >= 0))
-		http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, s->fe);
+		http_capture_bad_message(&s->be->invalid_rep, s, msg, msg->msg_state, sess->fe);
 
 	/*
 	 * 1: get the status code
@@ -6072,7 +6075,7 @@
 	s->logs.logwait &= ~LW_RESP;
 	if (unlikely((s->logs.logwait & LW_RSPHDR) && txn->rsp.cap))
 		capture_headers(rep->buf->p, &txn->hdr_idx,
-				txn->rsp.cap, s->fe->rsp_cap);
+				txn->rsp.cap, sess->fe->rsp_cap);
 
 	/* 4: determine the transfer-length.
 	 * According to RFC2616 #4.4, amended by the HTTPbis working group,
@@ -6171,7 +6174,7 @@
 		msg->body_len = msg->chunk_len = cl;
 	}
 
-	if (s->fe->comp || s->be->comp)
+	if (sess->fe->comp || s->be->comp)
 		select_compression_response_header(s, rep->buf);
 
 skip_content_length:
@@ -6207,13 +6210,13 @@
 	}
 	else if ((txn->status >= 200) && !(txn->flags & TX_HDR_CONN_PRS) &&
 		 ((txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN ||
-		  ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+		  ((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 		   (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL))) {
 		int to_del = 0;
 
 		/* this situation happens when combining pretend-keepalive with httpclose. */
 		if ((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL &&
-		    ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+		    ((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 		     (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL))
 			txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | TX_CON_WANT_CLO;
 
@@ -6327,8 +6330,8 @@
 	 * pointer and the ->fe rule list. If it doesn't match, I initialize
 	 * the loop with the ->be.
 	 */
-	if (s->current_rule_list == &s->fe->http_res_rules)
-		cur_proxy = s->fe;
+	if (s->current_rule_list == &sess->fe->http_res_rules)
+		cur_proxy = sess->fe;
 	else
 		cur_proxy = s->be;
 	while (1) {
@@ -6374,7 +6377,7 @@
 				objt_server(s->target)->counters.failed_secu++;
 
 			s->be->be_counters.denied_resp++;
-			s->fe->fe_counters.denied_resp++;
+			sess->fe->fe_counters.denied_resp++;
 			if (sess->listener->counters)
 				sess->listener->counters->denied_resp++;
 
@@ -6398,9 +6401,9 @@
 		}
 
 		/* check whether we're already working on the frontend */
-		if (cur_proxy == s->fe)
+		if (cur_proxy == sess->fe)
 			break;
-		cur_proxy = s->fe;
+		cur_proxy = sess->fe;
 	}
 
 	/* After this point, this anayzer can't return yield, so we can
@@ -6419,7 +6422,7 @@
 	/*
 	 * Now check for a server cookie.
 	 */
-	if (s->be->cookie_name || s->be->appsession_name || s->fe->capture_name ||
+	if (s->be->cookie_name || s->be->appsession_name || sess->fe->capture_name ||
 	    (s->be->options & PR_O_CHK_CACHE))
 		manage_server_side_cookies(s, rep);
 
@@ -6525,7 +6528,7 @@
 			objt_server(s->target)->counters.failed_secu++;
 
 		s->be->be_counters.denied_resp++;
-		s->fe->fe_counters.denied_resp++;
+		sess->fe->fe_counters.denied_resp++;
 		if (sess->listener->counters)
 			sess->listener->counters->denied_resp++;
 
@@ -6548,7 +6551,7 @@
 	 */
 	if ((txn->status != 101) && !(txn->flags & TX_HDR_CONN_UPG) &&
 	    (((txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) ||
-	     ((s->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
+	     ((sess->fe->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL ||
 	      (s->be->options & PR_O_HTTP_MODE) == PR_O_HTTP_PCL))) {
 		unsigned int want_flags = 0;
 
@@ -6581,7 +6584,7 @@
 	 * bytes from the server, then this is the right moment. We have
 	 * to temporarily assign bytes_out to log what we currently have.
 	 */
-	if (!LIST_ISEMPTY(&s->fe->logformat) && !(s->logs.logwait & LW_BYTES)) {
+	if (!LIST_ISEMPTY(&sess->fe->logformat) && !(s->logs.logwait & LW_BYTES)) {
 		s->logs.t_close = s->logs.t_data; /* to get a valid end date */
 		s->logs.bytes_out = txn->rsp.eoh;
 		s->do_log(s);
@@ -6621,6 +6624,7 @@
  */
 int http_response_forward_body(struct stream *s, struct channel *res, int an_bit)
 {
+	struct session *sess = s->sess;
 	struct http_txn *txn = &s->txn;
 	struct http_msg *msg = &s->txn.rsp;
 	static struct buffer *tmpbuf = &buf_empty;
@@ -6734,7 +6738,7 @@
 				goto missing_data;
 			else if (ret < 0) {
 				if (msg->err_pos >= 0)
-					http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_CHUNK_CRLF, s->fe);
+					http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_CHUNK_CRLF, sess->fe);
 				goto return_bad_res;
 			}
 			/* we're in MSG_CHUNK_SIZE now, fall through */
@@ -6750,7 +6754,7 @@
 				goto missing_data;
 			else if (ret < 0) {
 				if (msg->err_pos >= 0)
-					http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_CHUNK_SIZE, s->fe);
+					http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_CHUNK_SIZE, sess->fe);
 				goto return_bad_res;
 			}
 			/* otherwise we're in HTTP_MSG_DATA or HTTP_MSG_TRAILERS state */
@@ -6768,7 +6772,7 @@
 				goto missing_data;
 			else if (ret < 0) {
 				if (msg->err_pos >= 0)
-					http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_TRAILERS, s->fe);
+					http_capture_bad_message(&s->be->invalid_rep, s, msg, HTTP_MSG_TRAILERS, sess->fe);
 				goto return_bad_res;
 			}
 			/* we're in HTTP_MSG_DONE now, fall through */
@@ -6805,7 +6809,7 @@
 						goto aborted_xfer;
 					}
 					if (msg->err_pos >= 0)
-						http_capture_bad_message(&s->be->invalid_rep, s, msg, ret, s->fe);
+						http_capture_bad_message(&s->be->invalid_rep, s, msg, ret, sess->fe);
 					goto return_bad_res;
 				}
 				return 1;
@@ -6917,7 +6921,7 @@
 	res->analysers = 0;
 	s->req.analysers = 0; /* we're in data phase, we want to abort both directions */
 
-	s->fe->fe_counters.cli_aborts++;
+	sess->fe->fe_counters.cli_aborts++;
 	s->be->be_counters.cli_aborts++;
 	if (objt_server(s->target))
 		objt_server(s->target)->counters.cli_aborts++;
@@ -6976,7 +6980,7 @@
 				 * FIXME: should we return an HTTP/500 here so that
 				 * the admin knows there's a problem ?
 				 */
-				if (s->be != s->fe)
+				if (s->be != strm_sess(s)->fe)
 					break;
 
 				/* Swithing Proxy */
@@ -7077,7 +7081,7 @@
 			 * FIXME: should we return an HTTP/500 here so that
 			 * the admin knows there's a problem ?
 			 */
-			if (s->be != s->fe)
+			if (s->be != strm_sess(s)->fe)
 				break;
 
 			/* Swithing Proxy */
@@ -7351,6 +7355,7 @@
 void manage_client_side_cookies(struct stream *s, struct channel *req)
 {
 	struct http_txn *txn = &s->txn;
+	struct session *sess = s->sess;
 	int preserve_hdr;
 	int cur_idx, old_idx;
 	char *hdr_beg, *hdr_end, *hdr_next, *del_from;
@@ -7534,16 +7539,16 @@
 			 * can only capture one. Also as an optimisation, we ignore
 			 * cookies shorter than the declared name.
 			 */
-			if (s->fe->capture_name != NULL && txn->cli_cookie == NULL &&
-			    (val_end - att_beg >= s->fe->capture_namelen) &&
-			    memcmp(att_beg, s->fe->capture_name, s->fe->capture_namelen) == 0) {
+			if (sess->fe->capture_name != NULL && txn->cli_cookie == NULL &&
+			    (val_end - att_beg >= sess->fe->capture_namelen) &&
+			    memcmp(att_beg, sess->fe->capture_name, sess->fe->capture_namelen) == 0) {
 				int log_len = val_end - att_beg;
 
 				if ((txn->cli_cookie = pool_alloc2(pool2_capture)) == NULL) {
 					Alert("HTTP logging : out of memory.\n");
 				} else {
-					if (log_len > s->fe->capture_len)
-						log_len = s->fe->capture_len;
+					if (log_len > sess->fe->capture_len)
+						log_len = sess->fe->capture_len;
 					memcpy(txn->cli_cookie, att_beg, log_len);
 					txn->cli_cookie[log_len] = 0;
 				}
@@ -8024,6 +8029,7 @@
 void manage_server_side_cookies(struct stream *s, struct channel *res)
 {
 	struct http_txn *txn = &s->txn;
+	struct session *sess = s->sess;
 	struct server *srv;
 	int is_cookie2;
 	int cur_idx, old_idx, delta;
@@ -8074,7 +8080,7 @@
 		 */
 		if (s->be->cookie_name == NULL &&
 		    s->be->appsession_name == NULL &&
-		    s->fe->capture_name == NULL)
+		    sess->fe->capture_name == NULL)
 			return;
 
 		/* OK so now we know we have to process this response cookie.
@@ -8208,17 +8214,17 @@
 			 * can only capture one. Also as an optimisation, we ignore
 			 * cookies shorter than the declared name.
 			 */
-			if (s->fe->capture_name != NULL &&
+			if (sess->fe->capture_name != NULL &&
 			    txn->srv_cookie == NULL &&
-			    (val_end - att_beg >= s->fe->capture_namelen) &&
-			    memcmp(att_beg, s->fe->capture_name, s->fe->capture_namelen) == 0) {
+			    (val_end - att_beg >= sess->fe->capture_namelen) &&
+			    memcmp(att_beg, sess->fe->capture_name, sess->fe->capture_namelen) == 0) {
 				int log_len = val_end - att_beg;
 				if ((txn->srv_cookie = pool_alloc2(pool2_capture)) == NULL) {
 					Alert("HTTP logging : out of memory.\n");
 				}
 				else {
-					if (log_len > s->fe->capture_len)
-						log_len = s->fe->capture_len;
+					if (log_len > sess->fe->capture_len)
+						log_len = sess->fe->capture_len;
 					memcpy(txn->srv_cookie, att_beg, log_len);
 					txn->srv_cookie[log_len] = 0;
 				}
@@ -8783,7 +8789,7 @@
 void http_init_txn(struct stream *s)
 {
 	struct http_txn *txn = &s->txn;
-	struct proxy *fe = s->fe;
+	struct proxy *fe = strm_sess(s)->fe;
 
 	txn->flags = 0;
 	txn->status = -1;
@@ -8826,6 +8832,7 @@
 void http_end_txn(struct stream *s)
 {
 	struct http_txn *txn = &s->txn;
+	struct proxy *fe = strm_sess(s)->fe;
 
 	/* release any possible compression context */
 	if (s->flags & SF_COMP_READY)
@@ -8848,16 +8855,16 @@
 
 	if (txn->req.cap) {
 		struct cap_hdr *h;
-		for (h = s->fe->req_cap; h; h = h->next)
+		for (h = fe->req_cap; h; h = h->next)
 			pool_free2(h->pool, txn->req.cap[h->index]);
-		memset(txn->req.cap, 0, s->fe->nb_req_cap * sizeof(void *));
+		memset(txn->req.cap, 0, fe->nb_req_cap * sizeof(void *));
 	}
 
 	if (txn->rsp.cap) {
 		struct cap_hdr *h;
-		for (h = s->fe->rsp_cap; h; h = h->next)
+		for (h = fe->rsp_cap; h; h = h->next)
 			pool_free2(h->pool, txn->rsp.cap[h->index]);
-		memset(txn->rsp.cap, 0, s->fe->nb_rsp_cap * sizeof(void *));
+		memset(txn->rsp.cap, 0, fe->nb_rsp_cap * sizeof(void *));
 	}
 
 }
@@ -8873,8 +8880,8 @@
 	 */
 	s->current_rule_list = NULL;
 
-	s->be = s->fe;
-	s->logs.logwait = s->fe->to_log;
+	s->be = strm_sess(s)->fe;
+	s->logs.logwait = strm_sess(s)->fe->to_log;
 	s->logs.level = 0;
 	stream_del_srv_conn(s);
 	s->target = NULL;
@@ -8897,11 +8904,11 @@
 	if (unlikely(s->res.buf->i))
 		s->res.buf->i = 0;
 
-	s->req.rto = s->fe->timeout.client;
+	s->req.rto = strm_sess(s)->fe->timeout.client;
 	s->req.wto = TICK_ETERNITY;
 
 	s->res.rto = TICK_ETERNITY;
-	s->res.wto = s->fe->timeout.client;
+	s->res.wto = strm_sess(s)->fe->timeout.client;
 
 	s->req.rex = TICK_ETERNITY;
 	s->req.wex = TICK_ETERNITY;
@@ -10818,7 +10825,7 @@
 smp_fetch_capture_header_req(struct proxy *px, struct stream *l4, void *l7, unsigned int opt,
                  const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct proxy *fe = l4->fe;
+	struct proxy *fe = strm_sess(l4)->fe;
 	struct http_txn *txn = l7;
 	int idx;
 
@@ -10845,7 +10852,7 @@
 smp_fetch_capture_header_res(struct proxy *px, struct stream *l4, void *l7, unsigned int opt,
                  const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	struct proxy *fe = l4->fe;
+	struct proxy *fe = strm_sess(l4)->fe;
 	struct http_txn *txn = l7;
 	int idx;
 
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 338a0d2..67404cf 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -1154,7 +1154,7 @@
 				req->analysers = 0;
 
 				s->be->be_counters.denied_req++;
-				s->fe->fe_counters.denied_req++;
+				sess->fe->fe_counters.denied_req++;
 				if (sess->listener->counters)
 					sess->listener->counters->denied_req++;
 
@@ -1183,7 +1183,7 @@
 				if (key && (ts = stktable_get_entry(t, key))) {
 					stream_track_stkctr(&s->stkctr[tcp_trk_idx(rule->action)], t, ts);
 					stkctr_set_flags(&s->stkctr[tcp_trk_idx(rule->action)], STKCTR_TRACK_CONTENT);
-					if (s->fe != s->be)
+					if (sess->fe != s->be)
 						stkctr_set_flags(&s->stkctr[tcp_trk_idx(rule->action)], STKCTR_TRACK_BACKEND);
 				}
 			}
@@ -1316,7 +1316,7 @@
 				rep->analysers = 0;
 
 				s->be->be_counters.denied_resp++;
-				s->fe->fe_counters.denied_resp++;
+				sess->fe->fe_counters.denied_resp++;
 				if (sess->listener->counters)
 					sess->listener->counters->denied_resp++;
 
@@ -1373,11 +1373,11 @@
 	if (!conn)
 		return result;
 
-	list_for_each_entry(rule, &s->fe->tcp_req.l4_rules, list) {
+	list_for_each_entry(rule, &sess->fe->tcp_req.l4_rules, list) {
 		ret = ACL_TEST_PASS;
 
 		if (rule->cond) {
-			ret = acl_exec_cond(rule->cond, s->fe, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+			ret = acl_exec_cond(rule->cond, sess->fe, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 			ret = acl_pass(ret);
 			if (rule->cond->pol == ACL_COND_UNLESS)
 				ret = !ret;
@@ -1386,7 +1386,7 @@
 		if (ret) {
 			/* we have a matching rule. */
 			if (rule->action == TCP_ACT_REJECT) {
-				s->fe->fe_counters.denied_conn++;
+				sess->fe->fe_counters.denied_conn++;
 				if (sess->listener->counters)
 					sess->listener->counters->denied_conn++;
 
@@ -1418,7 +1418,7 @@
 			}
 			else {
 				/* Custom keywords. */
-				rule->action_ptr(rule, s->fe, s);
+				rule->action_ptr(rule, sess->fe, s);
 
 				/* otherwise it's an accept */
 				break;
diff --git a/src/proxy.c b/src/proxy.c
index 85d7562..9b23db0 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -960,8 +960,8 @@
 	 * have to re-adjust the desired keep-alive/close mode to accommodate
 	 * both the frontend's and the backend's modes.
 	 */
-	if (s->fe->mode == PR_MODE_HTTP && be->mode == PR_MODE_HTTP &&
-	    ((s->fe->options & PR_O_HTTP_MODE) != (be->options & PR_O_HTTP_MODE)))
+	if (strm_sess(s)->fe->mode == PR_MODE_HTTP && be->mode == PR_MODE_HTTP &&
+	    ((strm_sess(s)->fe->options & PR_O_HTTP_MODE) != (be->options & PR_O_HTTP_MODE)))
 		http_adjust_conn_mode(s, &s->txn, &s->txn.req);
 
 	/* If an LB algorithm needs to access some pre-parsed body contents,
diff --git a/src/stream.c b/src/stream.c
index 290c565..132e425 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -122,7 +122,7 @@
 		goto out_free_stream;
 
 	s->sess->listener = l;
-	s->fe  = p;
+	s->sess->fe  = p;
 
 	s->si[0].flags = SI_FL_NONE;
 	s->si[1].flags = SI_FL_ISBACK;
@@ -290,9 +290,9 @@
 	end = date2str_log(trash.str + trash.len, &tm, &(s->logs.accept_date), trash.size - trash.len);
 	trash.len = end - trash.str;
 	if (sess->listener->name)
-		chunk_appendf(&trash, "] %s/%s", s->fe->id, sess->listener->name);
+		chunk_appendf(&trash, "] %s/%s", sess->fe->id, sess->listener->name);
 	else
-		chunk_appendf(&trash, "] %s/%d", s->fe->id, sess->listener->luid);
+		chunk_appendf(&trash, "] %s/%d", sess->fe->id, sess->listener->luid);
 }
 
 /* This function kills an existing embryonic stream. It stops the connection's
@@ -308,10 +308,10 @@
 	unsigned int log = s->logs.logwait;
 	const char *err_msg;
 
-	if (s->fe->options2 & PR_O2_LOGERRORS)
+	if (sess->fe->options2 & PR_O2_LOGERRORS)
 		level = LOG_ERR;
 
-	if (log && (s->fe->options & PR_O_NULLNOLOG)) {
+	if (log && (sess->fe->options & PR_O_NULLNOLOG)) {
 		/* with "option dontlognull", we don't log connections with no transfer */
 		if (!conn->err_code ||
 		    conn->err_code == CO_ER_PRX_EMPTY || conn->err_code == CO_ER_PRX_ABORT ||
@@ -330,9 +330,9 @@
 		prepare_mini_sess_log_prefix(s);
 		err_msg = conn_err_code_str(conn);
 		if (err_msg)
-			send_log(s->fe, level, "%s: %s\n", trash.str, err_msg);
+			send_log(sess->fe, level, "%s: %s\n", trash.str, err_msg);
 		else
-			send_log(s->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n",
+			send_log(sess->fe, level, "%s: unknown connection error (code=%d flags=%08x)\n",
 				 trash.str, conn->err_code, conn->flags);
 	}
 
@@ -340,7 +340,7 @@
 	conn_force_close(conn);
 	conn_free(conn);
 
-	s->fe->feconn--;
+	sess->fe->feconn--;
 	stream_store_counters(s);
 
 	if (!(sess->listener->options & LI_O_UNLIMITED))
@@ -354,9 +354,9 @@
 	if (!LIST_ISEMPTY(&global_listener_queue))
 		dequeue_all_listeners(&global_listener_queue);
 
-	if (!LIST_ISEMPTY(&s->fe->listener_queue) &&
-	    (!s->fe->fe_sps_lim || freq_ctr_remain(&s->fe->fe_sess_per_sec, s->fe->fe_sps_lim, 0) > 0))
-		dequeue_all_listeners(&s->fe->listener_queue);
+	if (!LIST_ISEMPTY(&sess->fe->listener_queue) &&
+	    (!sess->fe->fe_sps_lim || freq_ctr_remain(&sess->fe->fe_sess_per_sec, sess->fe->fe_sps_lim, 0) > 0))
+		dequeue_all_listeners(&sess->fe->listener_queue);
 
 	task_delete(s->task);
 	task_free(s->task);
@@ -423,7 +423,7 @@
 {
 	struct session *sess = s->sess;
 	struct listener *l = sess->listener;
-	struct proxy *p = s->fe;
+	struct proxy *p = sess->fe;
 	struct http_txn *txn;
 	struct task *t = s->task;
 	struct connection *conn = __objt_conn(s->target);
@@ -448,7 +448,7 @@
 	 * This changes later when switching rules are executed or
 	 * when the default backend is assigned.
 	 */
-	s->be  = s->fe;
+	s->be  = sess->fe;
 	s->comp_algo = NULL;
 	s->req.buf = s->res.buf = NULL;
 
@@ -482,7 +482,7 @@
 	 */
 	si_attach_conn(&s->si[0], conn);
 
-	if (likely(s->fe->options2 & PR_O2_INDEPSTR))
+	if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
 		s->si[0].flags |= SI_FL_INDEP_STR;
 
 	/* pre-initialize the other side's stream interface to an INIT state. The
@@ -491,7 +491,7 @@
 	si_reset(&s->si[1]);
 	si_detach(&s->si[1]);
 
-	if (likely(s->fe->options2 & PR_O2_INDEPSTR))
+	if (likely(sess->fe->options2 & PR_O2_INDEPSTR))
 		s->si[1].flags |= SI_FL_INDEP_STR;
 
 	stream_init_srv_conn(s);
@@ -517,7 +517,7 @@
 	s->res.flags |= CF_ISRESP;
 	s->res.analysers = 0;
 
-	if (s->fe->options2 & PR_O2_NODELAY) {
+	if (sess->fe->options2 & PR_O2_NODELAY) {
 		s->req.flags |= CF_NEVER_WAIT;
 		s->res.flags |= CF_NEVER_WAIT;
 	}
@@ -591,7 +591,7 @@
 static void stream_free(struct stream *s)
 {
 	struct http_txn *txn = &s->txn;
-	struct proxy *fe = s->fe;
+	struct proxy *fe = strm_sess(s)->fe;
 	struct bref *bref, *back;
 	struct connection *cli_conn = objt_conn(s->si[0].end);
 	int i;
@@ -815,7 +815,7 @@
 	bytes = s->req.total - s->logs.bytes_in;
 	s->logs.bytes_in = s->req.total;
 	if (bytes) {
-		s->fe->fe_counters.bytes_in += bytes;
+		sess->fe->fe_counters.bytes_in += bytes;
 
 		s->be->be_counters.bytes_in += bytes;
 
@@ -847,7 +847,7 @@
 	bytes = s->res.total - s->logs.bytes_out;
 	s->logs.bytes_out = s->res.total;
 	if (bytes) {
-		s->fe->fe_counters.bytes_out += bytes;
+		sess->fe->fe_counters.bytes_out += bytes;
 
 		s->be->be_counters.bytes_out += bytes;
 
@@ -1071,7 +1071,7 @@
 	if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
 		/* if the user wants to log as soon as possible, without counting
 		 * bytes from the server, then this is the right moment. */
-		if (!LIST_ISEMPTY(&s->fe->logformat) && !(s->logs.logwait & LW_BYTES)) {
+		if (!LIST_ISEMPTY(&strm_sess(s)->fe->logformat) && !(s->logs.logwait & LW_BYTES)) {
 			s->logs.t_close = s->logs.t_connect; /* to get a valid end date */
 			s->do_log(s);
 		}
@@ -1081,7 +1081,7 @@
 		rep->flags |= CF_READ_DONTWAIT; /* a single read is enough to get response headers */
 	}
 
-	rep->analysers |= s->fe->fe_rsp_ana | s->be->be_rsp_ana;
+	rep->analysers |= strm_sess(s)->fe->fe_rsp_ana | s->be->be_rsp_ana;
 	rep->flags |= CF_READ_ATTACHED; /* producer is now attached */
 	if (req->flags & CF_WAKE_CONNECT) {
 		req->flags |= CF_WAKE_ONCE;
@@ -1274,7 +1274,7 @@
 	if (!(s->flags & SF_FINST_MASK)) {
 		if (s->si[1].state < SI_ST_REQ) {
 
-			s->fe->fe_counters.failed_req++;
+			strm_sess(s)->fe->fe_counters.failed_req++;
 			if (strm_sess(s)->listener->counters)
 				strm_sess(s)->listener->counters->failed_req++;
 
@@ -1379,6 +1379,7 @@
 static int process_switching_rules(struct stream *s, struct channel *req, int an_bit)
 {
 	struct persist_rule *prst_rule;
+	struct proxy *fe = strm_sess(s)->fe;
 
 	req->analysers &= ~an_bit;
 	req->analyse_exp = TICK_ETERNITY;
@@ -1396,11 +1397,11 @@
 	if (!(s->flags & SF_BE_ASSIGNED)) {
 		struct switching_rule *rule;
 
-		list_for_each_entry(rule, &s->fe->switching_rules, list) {
+		list_for_each_entry(rule, &fe->switching_rules, list) {
 			int ret = 1;
 
 			if (rule->cond) {
-				ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+				ret = acl_exec_cond(rule->cond, fe, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 				ret = acl_pass(ret);
 				if (rule->cond->pol == ACL_COND_UNLESS)
 					ret = !ret;
@@ -1436,12 +1437,12 @@
 		 * backend if any.
 		 */
 		if (!(s->flags & SF_BE_ASSIGNED))
-			if (!stream_set_backend(s, s->fe->defbe.be ? s->fe->defbe.be : s->be))
+			if (!stream_set_backend(s, fe->defbe.be ? fe->defbe.be : s->be))
 				goto sw_failed;
 	}
 
 	/* we don't want to run the TCP or HTTP filters again if the backend has not changed */
-	if (s->fe == s->be) {
+	if (fe == s->be) {
 		s->req.analysers &= ~AN_REQ_INSPECT_BE;
 		s->req.analysers &= ~AN_REQ_HTTP_PROCESS_BE;
 	}
@@ -1867,7 +1868,7 @@
 			stream_int_report_error(si_f);
 			if (!(req->analysers) && !(res->analysers)) {
 				s->be->be_counters.cli_aborts++;
-				s->fe->fe_counters.cli_aborts++;
+				sess->fe->fe_counters.cli_aborts++;
 				if (srv)
 					srv->counters.cli_aborts++;
 				if (!(s->flags & SF_ERR_MASK))
@@ -1888,7 +1889,7 @@
 				srv->counters.failed_resp++;
 			if (!(req->analysers) && !(res->analysers)) {
 				s->be->be_counters.srv_aborts++;
-				s->fe->fe_counters.srv_aborts++;
+				sess->fe->fe_counters.srv_aborts++;
 				if (srv)
 					srv->counters.srv_aborts++;
 				if (!(s->flags & SF_ERR_MASK))
@@ -2036,7 +2037,7 @@
 				}
 
 				if (ana_list & AN_REQ_HTTP_PROCESS_FE) {
-					if (!http_process_req_common(s, req, AN_REQ_HTTP_PROCESS_FE, s->fe))
+					if (!http_process_req_common(s, req, AN_REQ_HTTP_PROCESS_FE, sess->fe))
 						break;
 					UPDATE_ANALYSERS(req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE);
 				}
@@ -2235,28 +2236,28 @@
 			req->analysers = 0;
 			if (req->flags & CF_READ_ERROR) {
 				s->be->be_counters.cli_aborts++;
-				s->fe->fe_counters.cli_aborts++;
+				sess->fe->fe_counters.cli_aborts++;
 				if (srv)
 					srv->counters.cli_aborts++;
 				s->flags |= SF_ERR_CLICL;
 			}
 			else if (req->flags & CF_READ_TIMEOUT) {
 				s->be->be_counters.cli_aborts++;
-				s->fe->fe_counters.cli_aborts++;
+				sess->fe->fe_counters.cli_aborts++;
 				if (srv)
 					srv->counters.cli_aborts++;
 				s->flags |= SF_ERR_CLITO;
 			}
 			else if (req->flags & CF_WRITE_ERROR) {
 				s->be->be_counters.srv_aborts++;
-				s->fe->fe_counters.srv_aborts++;
+				sess->fe->fe_counters.srv_aborts++;
 				if (srv)
 					srv->counters.srv_aborts++;
 				s->flags |= SF_ERR_SRVCL;
 			}
 			else {
 				s->be->be_counters.srv_aborts++;
-				s->fe->fe_counters.srv_aborts++;
+				sess->fe->fe_counters.srv_aborts++;
 				if (srv)
 					srv->counters.srv_aborts++;
 				s->flags |= SF_ERR_SRVTO;
@@ -2268,28 +2269,28 @@
 			res->analysers = 0;
 			if (res->flags & CF_READ_ERROR) {
 				s->be->be_counters.srv_aborts++;
-				s->fe->fe_counters.srv_aborts++;
+				sess->fe->fe_counters.srv_aborts++;
 				if (srv)
 					srv->counters.srv_aborts++;
 				s->flags |= SF_ERR_SRVCL;
 			}
 			else if (res->flags & CF_READ_TIMEOUT) {
 				s->be->be_counters.srv_aborts++;
-				s->fe->fe_counters.srv_aborts++;
+				sess->fe->fe_counters.srv_aborts++;
 				if (srv)
 					srv->counters.srv_aborts++;
 				s->flags |= SF_ERR_SRVTO;
 			}
 			else if (res->flags & CF_WRITE_ERROR) {
 				s->be->be_counters.cli_aborts++;
-				s->fe->fe_counters.cli_aborts++;
+				sess->fe->fe_counters.cli_aborts++;
 				if (srv)
 					srv->counters.cli_aborts++;
 				s->flags |= SF_ERR_CLICL;
 			}
 			else {
 				s->be->be_counters.cli_aborts++;
-				s->fe->fe_counters.cli_aborts++;
+				sess->fe->fe_counters.cli_aborts++;
 				if (srv)
 					srv->counters.cli_aborts++;
 				s->flags |= SF_ERR_CLITO;
@@ -2336,8 +2337,8 @@
 	    (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->rcv_pipe) &&
 	    (objt_conn(si_b->end) && __objt_conn(si_b->end)->xprt && __objt_conn(si_b->end)->xprt->snd_pipe) &&
 	    (pipes_used < global.maxpipes) &&
-	    (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) ||
-	     (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
+	    (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) ||
+	     (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
 	      (req->flags & CF_STREAMER_FAST)))) {
 		req->flags |= CF_KERN_SPLICING;
 	}
@@ -2357,8 +2358,8 @@
 	if (unlikely((req->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CLOSE|CF_SHUTR)) ==
 		     (CF_AUTO_CLOSE|CF_SHUTR))) {
 		channel_shutw_now(req);
-		if (tick_isset(s->fe->timeout.clientfin)) {
-			res->wto = s->fe->timeout.clientfin;
+		if (tick_isset(sess->fe->timeout.clientfin)) {
+			res->wto = sess->fe->timeout.clientfin;
 			res->wex = tick_add(now_ms, res->wto);
 		}
 	}
@@ -2385,8 +2386,8 @@
 		if (si_f->flags & SI_FL_NOHALF)
 			si_f->flags |= SI_FL_NOLINGER;
 		si_shutr(si_f);
-		if (tick_isset(s->fe->timeout.clientfin)) {
-			res->wto = s->fe->timeout.clientfin;
+		if (tick_isset(sess->fe->timeout.clientfin)) {
+			res->wto = sess->fe->timeout.clientfin;
 			res->wex = tick_add(now_ms, res->wto);
 		}
 	}
@@ -2491,14 +2492,14 @@
 			req->rto = req->wto = res->rto = res->wto =
 				s->be->timeout.tunnel;
 
-			if ((req->flags & CF_SHUTR) && tick_isset(s->fe->timeout.clientfin))
-				res->wto = s->fe->timeout.clientfin;
+			if ((req->flags & CF_SHUTR) && tick_isset(sess->fe->timeout.clientfin))
+				res->wto = sess->fe->timeout.clientfin;
 			if ((req->flags & CF_SHUTW) && tick_isset(s->be->timeout.serverfin))
 				res->rto = s->be->timeout.serverfin;
 			if ((res->flags & CF_SHUTR) && tick_isset(s->be->timeout.serverfin))
 				req->wto = s->be->timeout.serverfin;
-			if ((res->flags & CF_SHUTW) && tick_isset(s->fe->timeout.clientfin))
-				req->rto = s->fe->timeout.clientfin;
+			if ((res->flags & CF_SHUTW) && tick_isset(sess->fe->timeout.clientfin))
+				req->rto = sess->fe->timeout.clientfin;
 
 			req->rex = tick_add(now_ms, req->rto);
 			req->wex = tick_add(now_ms, req->wto);
@@ -2514,8 +2515,8 @@
 	    (objt_conn(si_f->end) && __objt_conn(si_f->end)->xprt && __objt_conn(si_f->end)->xprt->snd_pipe) &&
 	    (objt_conn(si_b->end) && __objt_conn(si_b->end)->xprt && __objt_conn(si_b->end)->xprt->rcv_pipe) &&
 	    (pipes_used < global.maxpipes) &&
-	    (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) ||
-	     (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
+	    (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) ||
+	     (((sess->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) &&
 	      (res->flags & CF_STREAMER_FAST)))) {
 		res->flags |= CF_KERN_SPLICING;
 	}
@@ -2545,8 +2546,8 @@
 	if (unlikely((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW &&
 		     channel_is_empty(res))) {
 		si_shutw(si_f);
-		if (tick_isset(s->fe->timeout.clientfin)) {
-			req->rto = s->fe->timeout.clientfin;
+		if (tick_isset(sess->fe->timeout.clientfin)) {
+			req->rto = sess->fe->timeout.clientfin;
 			req->rex = tick_add(now_ms, req->rto);
 		}
 	}
@@ -2610,7 +2611,7 @@
 	if (likely((si_f->state != SI_ST_CLO) ||
 		   (si_b->state > SI_ST_INI && si_b->state < SI_ST_CLO))) {
 
-		if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SF_BE_ASSIGNED))
+		if ((sess->fe->options & PR_O_CONTSTATS) && (s->flags & SF_BE_ASSIGNED))
 			stream_process_counters(s);
 
 		if (si_f->state == SI_ST_EST && obj_type(si_f->end) != OBJ_TYPE_APPCTX)
@@ -2686,7 +2687,7 @@
 		return t; /* nothing more to do */
 	}
 
-	s->fe->feconn--;
+	sess->fe->feconn--;
 	if (s->flags & SF_BE_ASSIGNED)
 		s->be->beconn--;
 	jobs--;
@@ -2701,9 +2702,9 @@
 		if (!LIST_ISEMPTY(&global_listener_queue))
 			dequeue_all_listeners(&global_listener_queue);
 
-		if (!LIST_ISEMPTY(&s->fe->listener_queue) &&
-		    (!s->fe->fe_sps_lim || freq_ctr_remain(&s->fe->fe_sess_per_sec, s->fe->fe_sps_lim, 0) > 0))
-			dequeue_all_listeners(&s->fe->listener_queue);
+		if (!LIST_ISEMPTY(&sess->fe->listener_queue) &&
+		    (!sess->fe->fe_sps_lim || freq_ctr_remain(&sess->fe->fe_sess_per_sec, sess->fe->fe_sps_lim, 0) > 0))
+			dequeue_all_listeners(&sess->fe->listener_queue);
 	}
 
 	if (unlikely((global.mode & MODE_DEBUG) &&
@@ -2725,10 +2726,10 @@
 		if (n < 1 || n > 5)
 			n = 0;
 
-		if (s->fe->mode == PR_MODE_HTTP) {
-			s->fe->fe_counters.p.http.rsp[n]++;
+		if (sess->fe->mode == PR_MODE_HTTP) {
+			sess->fe->fe_counters.p.http.rsp[n]++;
 			if (s->comp_algo && (s->flags & SF_COMP_READY))
-				s->fe->fe_counters.p.http.comp_rsp++;
+				sess->fe->fe_counters.p.http.comp_rsp++;
 		}
 		if ((s->flags & SF_BE_ASSIGNED) &&
 		    (s->be->mode == PR_MODE_HTTP)) {
@@ -2740,9 +2741,9 @@
 	}
 
 	/* let's do a final log if we need it */
-	if (!LIST_ISEMPTY(&s->fe->logformat) && s->logs.logwait &&
+	if (!LIST_ISEMPTY(&sess->fe->logformat) && s->logs.logwait &&
 	    !(s->flags & SF_MONITOR) &&
-	    (!(s->fe->options & PR_O_NULLNOLOG) || req->total)) {
+	    (!(sess->fe->options & PR_O_NULLNOLOG) || req->total)) {
 		s->do_log(s);
 	}