MINOR: htx: Replace the function http_find_stline() by http_get_stline()

Now, we only return the start-line. If not found, NULL is returned. No lookup is
performed and the HTX message is no more updated. It is now the caller
responsibility to update the position of the start-line to the right value. So
when it is not found, i.e sl_pos is set to -1, it means the last start-line has
been already processed and the next one has not been inserted yet.

It is mandatory to rely on this kind of warranty to store 1xx informational
responses and final reponse in the same HTX message.
This commit is contained in:
Christopher Faulet 2019-05-13 14:41:27 +02:00 committed by Willy Tarreau
parent b77a1d26a4
commit 297fbb45fe
10 changed files with 51 additions and 65 deletions

View File

@ -30,7 +30,7 @@
extern struct buffer htx_err_chunks[HTTP_ERR_SIZE]; extern struct buffer htx_err_chunks[HTTP_ERR_SIZE];
struct htx_sl *http_find_stline(struct htx *htx); struct htx_sl *http_get_stline(struct htx *htx);
int http_find_header(const struct htx *htx, const struct ist name, struct http_hdr_ctx *ctx, int full); int http_find_header(const struct htx *htx, const struct ist name, struct http_hdr_ctx *ctx, int full);
int http_add_header(struct htx *htx, const struct ist n, const struct ist v); int http_add_header(struct htx *htx, const struct ist n, const struct ist v);
int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p2, const struct ist p3); int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p2, const struct ist p3);

View File

@ -743,7 +743,7 @@ int assign_server(struct stream *s)
else { else {
struct ist uri; struct ist uri;
uri = htx_sl_req_uri(http_find_stline(htxbuf(&s->req.buf))); uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf)));
srv = get_server_uh(s->be, uri.ptr, uri.len, prev_srv); srv = get_server_uh(s->be, uri.ptr, uri.len, prev_srv);
} }
break; break;
@ -760,7 +760,7 @@ int assign_server(struct stream *s)
else { else {
struct ist uri; struct ist uri;
uri = htx_sl_req_uri(http_find_stline(htxbuf(&s->req.buf))); uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf)));
srv = get_server_ph(s->be, uri.ptr, uri.len, prev_srv); srv = get_server_ph(s->be, uri.ptr, uri.len, prev_srv);
} }

View File

@ -1351,7 +1351,7 @@ int sha1_hosturi(struct stream *s)
return 0; return 0;
chunk_memcat(trash, ctx.value.ptr, ctx.value.len); chunk_memcat(trash, ctx.value.ptr, ctx.value.len);
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
if (!path.ptr) if (!path.ptr)
return 0; return 0;

View File

@ -414,7 +414,7 @@ trace_http_headers(struct stream *s, struct filter *filter,
if (IS_HTX_STRM(s)) { if (IS_HTX_STRM(s)) {
struct htx *htx = htxbuf(&msg->chn->buf); struct htx *htx = htxbuf(&msg->chn->buf);
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
int32_t pos; int32_t pos;
STRM_TRACE(conf, s, "\t%.*s %.*s %.*s", STRM_TRACE(conf, s, "\t%.*s %.*s %.*s",

View File

@ -3944,7 +3944,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
if (IS_HTX_STRM(s)) { if (IS_HTX_STRM(s)) {
/* HTX version */ /* HTX version */
struct htx *htx = htxbuf(&s->req.buf); struct htx *htx = htxbuf(&s->req.buf);
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist path; struct ist path;
unsigned long long len = 0; unsigned long long len = 0;
int32_t pos; int32_t pos;

View File

@ -209,7 +209,7 @@ struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol)
return NULL; return NULL;
} }
} }
sl = http_find_stline(htx); sl = http_get_stline(htx);
if (vol && !sl) { if (vol && !sl) {
/* The start-line was already forwarded, it is too late to fetch anything */ /* The start-line was already forwarded, it is too late to fetch anything */
return NULL; return NULL;
@ -434,7 +434,7 @@ static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char
/* ensure the indexes are not affected */ /* ensure the indexes are not affected */
return 0; return 0;
} }
sl = http_find_stline(htx); sl = http_get_stline(htx);
smp->flags |= SMP_F_CONST; smp->flags |= SMP_F_CONST;
smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl); smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl);
smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl); smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl);
@ -478,7 +478,7 @@ static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const cha
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
len = HTX_SL_REQ_VLEN(sl); len = HTX_SL_REQ_VLEN(sl);
ptr = HTX_SL_REQ_VPTR(sl); ptr = HTX_SL_REQ_VPTR(sl);
} }
@ -518,7 +518,7 @@ static int smp_fetch_stver(const struct arg *args, struct sample *smp, const cha
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
len = HTX_SL_RES_VLEN(sl); len = HTX_SL_RES_VLEN(sl);
ptr = HTX_SL_RES_VPTR(sl); ptr = HTX_SL_RES_VPTR(sl);
} }
@ -559,7 +559,7 @@ static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const ch
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
len = HTX_SL_RES_CLEN(sl); len = HTX_SL_RES_CLEN(sl);
ptr = HTX_SL_RES_CPTR(sl); ptr = HTX_SL_RES_CPTR(sl);
} }
@ -1009,7 +1009,7 @@ static int smp_fetch_url(const struct arg *args, struct sample *smp, const char
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
smp->data.type = SMP_T_STR; smp->data.type = SMP_T_STR;
smp->data.u.str.area = HTX_SL_REQ_UPTR(sl); smp->data.u.str.area = HTX_SL_REQ_UPTR(sl);
smp->data.u.str.data = HTX_SL_REQ_ULEN(sl); smp->data.u.str.data = HTX_SL_REQ_ULEN(sl);
@ -1041,7 +1041,7 @@ static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const ch
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL); url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
} }
else { else {
@ -1074,7 +1074,7 @@ static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL); url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
} }
else { else {
@ -1573,7 +1573,7 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
if (!path.ptr) if (!path.ptr)
return 0; return 0;
@ -1643,7 +1643,7 @@ static int smp_fetch_base(const struct arg *args, struct sample *smp, const char
chunk_memcat(temp, ctx.value.ptr, ctx.value.len); chunk_memcat(temp, ctx.value.ptr, ctx.value.len);
/* now retrieve the path */ /* now retrieve the path */
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
if (path.ptr) { if (path.ptr) {
size_t len; size_t len;
@ -1728,7 +1728,7 @@ static int smp_fetch_base32(const struct arg *args, struct sample *smp, const ch
} }
/* now retrieve the path */ /* now retrieve the path */
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
if (path.ptr) { if (path.ptr) {
size_t len; size_t len;
@ -1844,7 +1844,7 @@ static int smp_fetch_query(const struct arg *args, struct sample *smp, const cha
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
ptr = HTX_SL_REQ_UPTR(sl); ptr = HTX_SL_REQ_UPTR(sl);
end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
} }
@ -2523,7 +2523,7 @@ static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const
if (!htx) if (!htx)
return 0; return 0;
sl = http_find_stline(htx); sl = http_get_stline(htx);
smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim); smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim);
if (!smp->ctx.a[0]) if (!smp->ctx.a[0])
return 0; return 0;
@ -2701,7 +2701,7 @@ static int smp_fetch_url32(const struct arg *args, struct sample *smp, const cha
} }
/* now retrieve the path */ /* now retrieve the path */
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
while (path.len > 0 && *(path.ptr) != '?') { while (path.len > 0 && *(path.ptr) != '?') {
path.ptr++; path.ptr++;

View File

@ -20,35 +20,21 @@
struct buffer htx_err_chunks[HTTP_ERR_SIZE]; struct buffer htx_err_chunks[HTTP_ERR_SIZE];
/* Finds the start line in the HTX message stopping at the first /* Returns the next unporocessed start line in the HTX message. It returns NULL
* end-of-message. It returns NULL when not found, otherwise, it returns the * is the start-line is undefined (sl_pos == 1). Otherwise, it returns the
* pointer on the htx_sl structure. The HTX message may be updated if the * pointer on the htx_sl structure.
* start-line is returned following a lookup.
*/ */
struct htx_sl *http_find_stline(struct htx *htx) struct htx_sl *http_get_stline(struct htx *htx)
{ {
struct htx_sl *sl = NULL; struct htx_blk *blk;
int32_t pos;
sl = htx_get_stline(htx); if (htx->sl_pos == -1)
if (sl) return NULL;
return sl;
for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) { blk = htx_get_blk(htx, htx->sl_pos);
struct htx_blk *blk = htx_get_blk(htx, pos); if (!blk)
enum htx_blk_type type = htx_get_blk_type(blk); return NULL;
return htx_get_blk_ptr(htx, blk);
if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) {
sl = htx_get_blk_ptr(htx, blk);
htx->sl_pos = pos;
break;
}
if (type == HTX_BLK_EOH || type == HTX_BLK_EOM)
break;
}
return sl;
} }
/* Finds the first or next occurrence of header <name> in the HTX message <htx> /* Finds the first or next occurrence of header <name> in the HTX message <htx>
@ -213,7 +199,7 @@ int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p
int http_replace_req_meth(struct htx *htx, const struct ist meth) int http_replace_req_meth(struct htx *htx, const struct ist meth)
{ {
struct buffer *temp = get_trash_chunk(); struct buffer *temp = get_trash_chunk();
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist uri, vsn; struct ist uri, vsn;
if (!sl) if (!sl)
@ -237,7 +223,7 @@ int http_replace_req_meth(struct htx *htx, const struct ist meth)
int http_replace_req_uri(struct htx *htx, const struct ist uri) int http_replace_req_uri(struct htx *htx, const struct ist uri)
{ {
struct buffer *temp = get_trash_chunk(); struct buffer *temp = get_trash_chunk();
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist meth, vsn; struct ist meth, vsn;
if (!sl) if (!sl)
@ -260,7 +246,7 @@ int http_replace_req_uri(struct htx *htx, const struct ist uri)
int http_replace_req_path(struct htx *htx, const struct ist path) int http_replace_req_path(struct htx *htx, const struct ist path)
{ {
struct buffer *temp = get_trash_chunk(); struct buffer *temp = get_trash_chunk();
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist meth, uri, vsn, p; struct ist meth, uri, vsn, p;
size_t plen = 0; size_t plen = 0;
@ -297,7 +283,7 @@ int http_replace_req_path(struct htx *htx, const struct ist path)
int http_replace_req_query(struct htx *htx, const struct ist query) int http_replace_req_query(struct htx *htx, const struct ist query)
{ {
struct buffer *temp = get_trash_chunk(); struct buffer *temp = get_trash_chunk();
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist meth, uri, vsn, q; struct ist meth, uri, vsn, q;
int offset = 1; int offset = 1;
@ -342,7 +328,7 @@ int http_replace_req_query(struct htx *htx, const struct ist query)
int http_replace_res_status(struct htx *htx, const struct ist status) int http_replace_res_status(struct htx *htx, const struct ist status)
{ {
struct buffer *temp = get_trash_chunk(); struct buffer *temp = get_trash_chunk();
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist vsn, reason; struct ist vsn, reason;
if (!sl) if (!sl)
@ -366,7 +352,7 @@ int http_replace_res_status(struct htx *htx, const struct ist status)
int http_replace_res_reason(struct htx *htx, const struct ist reason) int http_replace_res_reason(struct htx *htx, const struct ist reason)
{ {
struct buffer *temp = get_trash_chunk(); struct buffer *temp = get_trash_chunk();
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist vsn, status; struct ist vsn, status;
if (!sl) if (!sl)

View File

@ -291,7 +291,7 @@ int htx_wait_for_request(struct stream *s, struct channel *req, int an_bit)
txn->flags &= ~TX_WAIT_NEXT_RQ; txn->flags &= ~TX_WAIT_NEXT_RQ;
req->analyse_exp = TICK_ETERNITY; req->analyse_exp = TICK_ETERNITY;
sl = http_find_stline(htx); sl = http_get_stline(htx);
/* 0: we might have to print this header in debug mode */ /* 0: we might have to print this header in debug mode */
if (unlikely((global.mode & MODE_DEBUG) && if (unlikely((global.mode & MODE_DEBUG) &&
@ -801,7 +801,7 @@ int htx_process_request(struct stream *s, struct channel *req, int an_bit)
return 0; return 0;
} }
sl = http_find_stline(htx); sl = http_get_stline(htx);
uri = htx_sl_req_uri(sl); uri = htx_sl_req_uri(sl);
path = http_get_path(uri); path = http_get_path(uri);
if (url2sa(uri.ptr, uri.len - path.len, &conn->addr.to, NULL) == -1) if (url2sa(uri.ptr, uri.len - path.len, &conn->addr.to, NULL) == -1)
@ -1646,7 +1646,7 @@ int htx_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
*/ */
msg->msg_state = HTTP_MSG_BODY; msg->msg_state = HTTP_MSG_BODY;
sl = http_find_stline(htx); sl = http_get_stline(htx);
/* 0: we might have to print this header in debug mode */ /* 0: we might have to print this header in debug mode */
if (unlikely((global.mode & MODE_DEBUG) && if (unlikely((global.mode & MODE_DEBUG) &&
@ -2414,7 +2414,7 @@ int htx_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struct
if (http_find_header(htx, ist("Host"), &ctx, 0)) if (http_find_header(htx, ist("Host"), &ctx, 0))
host = ctx.value; host = ctx.value;
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
/* build message using path */ /* build message using path */
if (path.ptr) { if (path.ptr) {
@ -2462,7 +2462,7 @@ int htx_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struct
case REDIRECT_TYPE_PREFIX: { case REDIRECT_TYPE_PREFIX: {
struct ist path; struct ist path;
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
/* build message using path */ /* build message using path */
if (path.ptr) { if (path.ptr) {
@ -3639,11 +3639,11 @@ static int htx_apply_filter_to_req_line(struct stream *s, struct channel *req, s
done = 0; done = 0;
reqline->data = htx_fmt_req_line(http_find_stline(htx), reqline->area, reqline->size); reqline->data = htx_fmt_req_line(http_get_stline(htx), reqline->area, reqline->size);
/* Now we have the request line between cur_ptr and cur_end */ /* Now we have the request line between cur_ptr and cur_end */
if (regex_exec_match2(exp->preg, reqline->area, reqline->data, MAX_MATCH, pmatch, 0)) { if (regex_exec_match2(exp->preg, reqline->area, reqline->data, MAX_MATCH, pmatch, 0)) {
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist meth, uri, vsn; struct ist meth, uri, vsn;
int len; int len;
@ -3850,11 +3850,11 @@ static int htx_apply_filter_to_sts_line(struct stream *s, struct channel *res, s
return 0; return 0;
done = 0; done = 0;
resline->data = htx_fmt_res_line(http_find_stline(htx), resline->area, resline->size); resline->data = htx_fmt_res_line(http_get_stline(htx), resline->area, resline->size);
/* Now we have the status line between cur_ptr and cur_end */ /* Now we have the status line between cur_ptr and cur_end */
if (regex_exec_match2(exp->preg, resline->area, resline->data, MAX_MATCH, pmatch, 0)) { if (regex_exec_match2(exp->preg, resline->area, resline->data, MAX_MATCH, pmatch, 0)) {
struct htx_sl *sl = http_find_stline(htx); struct htx_sl *sl = http_get_stline(htx);
struct ist vsn, code, reason; struct ist vsn, code, reason;
int len; int len;
@ -4847,7 +4847,7 @@ static int htx_stats_check_uri(struct stream *s, struct http_txn *txn, struct pr
return 0; return 0;
htx = htxbuf(&s->req.buf); htx = htxbuf(&s->req.buf);
sl = http_find_stline(htx); sl = http_get_stline(htx);
uri = htx_sl_req_uri(sl); uri = htx_sl_req_uri(sl);
/* check URI size */ /* check URI size */
@ -4890,7 +4890,7 @@ static int htx_handle_stats(struct stream *s, struct channel *req)
appctx->ctx.stats.flags |= STAT_CHUNKED; appctx->ctx.stats.flags |= STAT_CHUNKED;
htx = htxbuf(&req->buf); htx = htxbuf(&req->buf);
sl = http_find_stline(htx); sl = http_get_stline(htx);
lookup = HTX_SL_REQ_UPTR(sl) + uri_auth->uri_len; lookup = HTX_SL_REQ_UPTR(sl) + uri_auth->uri_len;
end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
@ -5043,7 +5043,7 @@ void htx_perform_server_redirect(struct stream *s, struct stream_interface *si)
/* 2: add the request Path */ /* 2: add the request Path */
htx = htxbuf(&req->buf); htx = htxbuf(&req->buf);
sl = http_find_stline(htx); sl = http_get_stline(htx);
path = http_get_path(htx_sl_req_uri(sl)); path = http_get_path(htx_sl_req_uri(sl));
if (!path.ptr) if (!path.ptr)
return; return;

View File

@ -277,7 +277,7 @@ static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interfac
if (IS_HTX_STRM(si_strm(si))) { if (IS_HTX_STRM(si_strm(si))) {
struct channel *req = si_oc(si); struct channel *req = si_oc(si);
struct htx *htx = htxbuf(&req->buf); struct htx *htx = htxbuf(&req->buf);
struct ist uri = htx_sl_req_uri(http_find_stline(htx)); struct ist uri = htx_sl_req_uri(http_get_stline(htx));
p = uri.ptr; p = uri.ptr;
} }

View File

@ -1305,7 +1305,7 @@ int si_cs_recv(struct conn_stream *cs)
htx = htxbuf(&ic->buf); htx = htxbuf(&ic->buf);
if (htx) { if (htx) {
sl = http_find_stline(htx); sl = http_get_stline(htx);
if (sl && l7_status_match(si_strm(si)->be, if (sl && l7_status_match(si_strm(si)->be,
sl->info.res.status)) { sl->info.res.status)) {
/* If we got a status for which we would /* If we got a status for which we would