mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2024-12-13 15:04:42 +00:00
MEDIUM: backend: Remove code relying on the HTTP legacy mode
The L7 loadbalancing algorithms are concerned (uri, url_param and hdr), the "sni" parameter on the server line and the "source" parameter on the server line when used with "use_src hdr_ip()".
This commit is contained in:
parent
4cb2828e96
commit
7d37fbb753
100
src/backend.c
100
src/backend.c
@ -321,6 +321,8 @@ static struct server *get_server_ph_post(struct stream *s, const struct server *
|
||||
unsigned int hash = 0;
|
||||
struct channel *req = &s->req;
|
||||
struct proxy *px = s->be;
|
||||
struct htx *htx = htxbuf(&req->buf);
|
||||
struct htx_blk *blk;
|
||||
unsigned int plen = px->lbprm.arg_len;
|
||||
unsigned long len;
|
||||
const char *params, *p, *start, *end;
|
||||
@ -328,23 +330,6 @@ static struct server *get_server_ph_post(struct stream *s, const struct server *
|
||||
if (px->lbprm.tot_weight == 0)
|
||||
return NULL;
|
||||
|
||||
if (!IS_HTX_STRM(s)) {
|
||||
struct http_txn *txn = s->txn;
|
||||
struct http_msg *msg = &txn->req;
|
||||
|
||||
len = http_body_bytes(msg);
|
||||
p = params = c_ptr(req, -http_data_rewind(msg));
|
||||
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
if (len > b_wrap(&req->buf) - p)
|
||||
len = b_wrap(&req->buf) - p;
|
||||
|
||||
}
|
||||
else {
|
||||
struct htx *htx = htxbuf(&req->buf);
|
||||
struct htx_blk *blk;
|
||||
|
||||
p = params = NULL;
|
||||
len = 0;
|
||||
for (blk = htx_get_first_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
|
||||
@ -358,7 +343,6 @@ static struct server *get_server_ph_post(struct stream *s, const struct server *
|
||||
len = v.len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (len > plen) {
|
||||
/* Look for the parameter name followed by an equal symbol */
|
||||
@ -428,6 +412,8 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
|
||||
unsigned long len;
|
||||
const char *p;
|
||||
const char *start, *end;
|
||||
struct htx *htx = htxbuf(&s->req.buf);
|
||||
struct http_hdr_ctx ctx = { .blk = NULL };
|
||||
|
||||
/* tot_weight appears to mean srv_count */
|
||||
if (px->lbprm.tot_weight == 0)
|
||||
@ -437,28 +423,6 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
|
||||
if (px->lbprm.tot_used == 1)
|
||||
goto hash_done;
|
||||
|
||||
if (!IS_HTX_STRM(s)) {
|
||||
struct http_txn *txn = s->txn;
|
||||
struct hdr_ctx ctx = { .idx = 0 };
|
||||
|
||||
/* if the message is chunked, we skip the chunk size, but use the value as len */
|
||||
http_find_header2(px->lbprm.arg_str, plen, c_ptr(&s->req, -http_hdr_rewind(&txn->req)),
|
||||
&txn->hdr_idx, &ctx);
|
||||
|
||||
/* if the header is not found or empty, let's fallback to round robin */
|
||||
if (!ctx.idx || !ctx.vlen)
|
||||
return NULL;
|
||||
|
||||
/* Found the param_name in the headers.
|
||||
* we will compute the hash based on this value ctx.val.
|
||||
*/
|
||||
len = ctx.vlen;
|
||||
p = (char *)ctx.line + ctx.val;
|
||||
}
|
||||
else {
|
||||
struct htx *htx = htxbuf(&s->req.buf);
|
||||
struct http_hdr_ctx ctx = { .blk = NULL };
|
||||
|
||||
http_find_header(htx, ist2(px->lbprm.arg_str, plen), &ctx, 0);
|
||||
|
||||
/* if the header is not found or empty, let's fallback to round robin */
|
||||
@ -470,7 +434,6 @@ static struct server *get_server_hh(struct stream *s, const struct server *avoid
|
||||
*/
|
||||
len = ctx.value.len;
|
||||
p = ctx.value.ptr;
|
||||
}
|
||||
|
||||
if (!px->lbprm.arg_opt1) {
|
||||
hash = gen_hash(px, p, len);
|
||||
@ -734,13 +697,7 @@ int assign_server(struct stream *s)
|
||||
|
||||
case BE_LB_HASH_URI:
|
||||
/* URI hashing */
|
||||
if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
|
||||
break;
|
||||
if (!IS_HTX_STRM(s))
|
||||
srv = get_server_uh(s->be,
|
||||
c_ptr(&s->req, -http_uri_rewind(&s->txn->req)),
|
||||
s->txn->req.sl.rq.u_l, prev_srv);
|
||||
else {
|
||||
if (IS_HTX_STRM(s) && s->txn->req.msg_state >= HTTP_MSG_BODY) {
|
||||
struct ist uri;
|
||||
|
||||
uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf)));
|
||||
@ -750,28 +707,20 @@ int assign_server(struct stream *s)
|
||||
|
||||
case BE_LB_HASH_PRM:
|
||||
/* URL Parameter hashing */
|
||||
if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
|
||||
break;
|
||||
|
||||
if (!IS_HTX_STRM(s))
|
||||
srv = get_server_ph(s->be,
|
||||
c_ptr(&s->req, -http_uri_rewind(&s->txn->req)),
|
||||
s->txn->req.sl.rq.u_l, prev_srv);
|
||||
else {
|
||||
if (IS_HTX_STRM(s) && s->txn->req.msg_state >= HTTP_MSG_BODY) {
|
||||
struct ist uri;
|
||||
|
||||
uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf)));
|
||||
srv = get_server_ph(s->be, uri.ptr, uri.len, prev_srv);
|
||||
}
|
||||
|
||||
if (!srv && s->txn->meth == HTTP_METH_POST)
|
||||
srv = get_server_ph_post(s, prev_srv);
|
||||
}
|
||||
break;
|
||||
|
||||
case BE_LB_HASH_HDR:
|
||||
/* Header Parameter hashing */
|
||||
if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
|
||||
break;
|
||||
if (IS_HTX_STRM(s) && s->txn->req.msg_state >= HTTP_MSG_BODY)
|
||||
srv = get_server_hh(s, prev_srv);
|
||||
break;
|
||||
|
||||
@ -1103,7 +1052,7 @@ static void assign_tproxy_address(struct stream *s)
|
||||
memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
|
||||
break;
|
||||
case CO_SRC_TPROXY_DYN:
|
||||
if (src->bind_hdr_occ && s->txn) {
|
||||
if (src->bind_hdr_occ && IS_HTX_STRM(s)) {
|
||||
char *vptr;
|
||||
size_t vlen;
|
||||
|
||||
@ -1111,18 +1060,7 @@ static void assign_tproxy_address(struct stream *s)
|
||||
((struct sockaddr_in *)&srv_conn->addr.from)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)&srv_conn->addr.from)->sin_port = 0;
|
||||
((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr = 0;
|
||||
if (!IS_HTX_STRM(s)) {
|
||||
int rewind;
|
||||
|
||||
c_rew(&s->req, rewind = http_hdr_rewind(&s->txn->req));
|
||||
if (http_get_hdr(&s->txn->req, src->bind_hdr_name, src->bind_hdr_len,
|
||||
&s->txn->hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr =
|
||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||
}
|
||||
c_adv(&s->req, rewind);
|
||||
}
|
||||
else {
|
||||
if (http_get_htx_hdr(htxbuf(&s->req.buf),
|
||||
ist2(src->bind_hdr_name, src->bind_hdr_len),
|
||||
src->bind_hdr_occ, NULL, &vptr, &vlen)) {
|
||||
@ -1130,7 +1068,6 @@ static void assign_tproxy_address(struct stream *s)
|
||||
htonl(inetaddr_host_lim(vptr, vptr + vlen));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
|
||||
@ -1637,28 +1574,9 @@ int connect_server(struct stream *s)
|
||||
#ifdef USE_OPENSSL
|
||||
if (srv->ssl_ctx.sni) {
|
||||
struct sample *smp;
|
||||
int rewind;
|
||||
|
||||
if (!IS_HTX_STRM(s)) {
|
||||
/* Tricky case : we have already scheduled the pending
|
||||
* HTTP request or TCP data for leaving. So in HTTP we
|
||||
* rewind exactly the headers, otherwise we rewind the
|
||||
* output data.
|
||||
*/
|
||||
rewind = s->txn ? http_hdr_rewind(&s->txn->req) : co_data(&s->req);
|
||||
c_rew(&s->req, rewind);
|
||||
|
||||
smp = sample_fetch_as_type(s->be, s->sess, s, SMP_OPT_DIR_REQ | SMP_OPT_FINAL,
|
||||
srv->ssl_ctx.sni, SMP_T_STR);
|
||||
|
||||
/* restore the pointers */
|
||||
c_adv(&s->req, rewind);
|
||||
}
|
||||
else {
|
||||
smp = sample_fetch_as_type(s->be, s->sess, s, SMP_OPT_DIR_REQ | SMP_OPT_FINAL,
|
||||
srv->ssl_ctx.sni, SMP_T_STR);
|
||||
}
|
||||
|
||||
if (smp_make_safe(smp)) {
|
||||
ssl_sock_set_servername(srv_conn,
|
||||
smp->data.u.str.area);
|
||||
|
Loading…
Reference in New Issue
Block a user