]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Replace the function http_find_stline() by http_get_stline()
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 13 May 2019 12:41:27 +0000 (14:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 May 2019 05:42:12 +0000 (07:42 +0200)
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.

include/proto/http_htx.h
src/backend.c
src/cache.c
src/flt_trace.c
src/hlua.c
src/http_fetch.c
src/http_htx.c
src/proto_htx.c
src/stats.c
src/stream_interface.c

index 6028292d294431d9a6607014089e7bdbe621eb7f..a134052234a70d13b2b3c56beb93321a3dd1e8f2 100644 (file)
@@ -30,7 +30,7 @@
 
 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_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);
index 4dff185ec5e60c6f35c58fcfc04b3d99aed5cde4..fc006666580011d0746964fbce964b1762ef6b4b 100644 (file)
@@ -743,7 +743,7 @@ int assign_server(struct stream *s)
                                else {
                                        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);
                                }
                                break;
@@ -760,7 +760,7 @@ int assign_server(struct stream *s)
                                else {
                                        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);
                                }
 
index 7402e5efd874e067a73ee59a5972190dab74f561..188efea177b1bfb161b98a94e64bde7b3afe657a 100644 (file)
@@ -1351,7 +1351,7 @@ int sha1_hosturi(struct stream *s)
                        return 0;
                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));
                 if (!path.ptr)
                         return 0;
index 3cfd842ce1aa89e448dc3860b2dcbfee12bcbef2..ed159e8a7c10156251e29de752ccaf385398cce6 100644 (file)
@@ -414,7 +414,7 @@ trace_http_headers(struct stream *s, struct filter *filter,
 
        if (IS_HTX_STRM(s)) {
                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;
 
                STRM_TRACE(conf, s, "\t%.*s %.*s %.*s",
index f8e481c27a114c0dfe749e7ab6f2936e6751a059..72ce6bab60059c1ba1aa3d1f82903cbaf4ae4e25 100644 (file)
@@ -3944,7 +3944,7 @@ static int hlua_applet_http_new(lua_State *L, struct appctx *ctx)
        if (IS_HTX_STRM(s)) {
                /* HTX version */
                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;
                unsigned long long len = 0;
                int32_t pos;
index e16d7bf4c3bcd4ddebd62abc381bebcdc7e12039..0a5a2f91f79abe0cb7d8081e123f52a622cbefb2 100644 (file)
@@ -209,7 +209,7 @@ struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol)
                                return NULL;
                        }
                }
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                if (vol && !sl) {
                        /* The start-line was already forwarded, it is too late to fetch anything */
                        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 */
                                return 0;
                        }
-                       sl = http_find_stline(htx);
+                       sl = http_get_stline(htx);
                        smp->flags |= SMP_F_CONST;
                        smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(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)
                        return 0;
 
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                len = HTX_SL_REQ_VLEN(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)
                        return 0;
 
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                len = HTX_SL_RES_VLEN(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)
                        return 0;
 
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                len = HTX_SL_RES_CLEN(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)
                        return 0;
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                smp->data.type = SMP_T_STR;
                smp->data.u.str.area = HTX_SL_REQ_UPTR(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)
                        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);
        }
        else {
@@ -1074,7 +1074,7 @@ static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const
 
                if (!htx)
                        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);
        }
        else {
@@ -1573,7 +1573,7 @@ static int smp_fetch_path(const struct arg *args, struct sample *smp, const char
                if (!htx)
                        return 0;
 
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                path = http_get_path(htx_sl_req_uri(sl));
                if (!path.ptr)
                        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);
 
                /* now retrieve the path */
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                path = http_get_path(htx_sl_req_uri(sl));
                if (path.ptr) {
                        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 */
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                path = http_get_path(htx_sl_req_uri(sl));
                if (path.ptr) {
                        size_t len;
@@ -1844,7 +1844,7 @@ static int smp_fetch_query(const struct arg *args, struct sample *smp, const cha
                if (!htx)
                        return 0;
 
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                ptr = HTX_SL_REQ_UPTR(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)
                                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);
                        if (!smp->ctx.a[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 */
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                path = http_get_path(htx_sl_req_uri(sl));
                while (path.len > 0 && *(path.ptr) != '?') {
                        path.ptr++;
index e6332f7da9d96269e88997e721e9b254c920ffbc..e55420c4073fe8edb265801a17c781f696720362 100644 (file)
 
 struct buffer htx_err_chunks[HTTP_ERR_SIZE];
 
-/* Finds the start line in the HTX message stopping at the first
- * end-of-message. It returns NULL when not found, otherwise, it returns the
- * pointer on the htx_sl structure. The HTX message may be updated if the
- * start-line is returned following a lookup.
+/* Returns the next unporocessed start line in the HTX message. It returns NULL
+ * is the start-line is undefined (sl_pos == 1). Otherwise, it returns the
+ * pointer on the htx_sl structure.
  */
-struct htx_sl *http_find_stline(struct htx *htx)
+struct htx_sl *http_get_stline(struct htx *htx)
 {
-       struct htx_sl *sl = NULL;
-       int32_t pos;
-
-       sl = htx_get_stline(htx);
-       if (sl)
-               return sl;
-
-       for (pos = htx_get_head(htx); pos != -1; pos = htx_get_next(htx, pos)) {
-               struct htx_blk    *blk  = htx_get_blk(htx, pos);
-               enum htx_blk_type  type = htx_get_blk_type(blk);
-
-               if (type == HTX_BLK_REQ_SL || type == HTX_BLK_RES_SL) {
-                       sl = htx_get_blk_ptr(htx, blk);
-                       htx->sl_pos = pos;
-                       break;
-               }
+       struct htx_blk *blk;
 
-               if (type == HTX_BLK_EOH || type == HTX_BLK_EOM)
-                       break;
-       }
+       if (htx->sl_pos == -1)
+               return NULL;
 
-       return sl;
+       blk = htx_get_blk(htx, htx->sl_pos);
+       if (!blk)
+               return NULL;
+       return htx_get_blk_ptr(htx, blk);
 }
 
 /* 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)
 {
        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;
 
        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)
 {
        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;
 
        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)
 {
        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;
        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)
 {
        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;
        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)
 {
        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;
 
        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)
 {
        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;
 
        if (!sl)
index 8838fd77cbeca5ec91bef38b147be0fbe3d06202..35039fc5355f6bc1790240fca5b75d864e2cca37 100644 (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;
        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 */
        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;
                }
-               sl = http_find_stline(htx);
+               sl = http_get_stline(htx);
                uri = htx_sl_req_uri(sl);
                path = http_get_path(uri);
                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;
-       sl = http_find_stline(htx);
+       sl = http_get_stline(htx);
 
        /* 0: we might have to print this header in debug mode */
        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))
                                host = ctx.value;
 
-                       sl = http_find_stline(htx);
+                       sl = http_get_stline(htx);
                        path = http_get_path(htx_sl_req_uri(sl));
                        /* build message using path */
                        if (path.ptr) {
@@ -2462,7 +2462,7 @@ int htx_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struct
                case REDIRECT_TYPE_PREFIX: {
                        struct ist path;
 
-                       sl = http_find_stline(htx);
+                       sl = http_get_stline(htx);
                        path = http_get_path(htx_sl_req_uri(sl));
                        /* build message using path */
                        if (path.ptr) {
@@ -3639,11 +3639,11 @@ static int htx_apply_filter_to_req_line(struct stream *s, struct channel *req, s
 
        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 */
        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;
                int len;
 
@@ -3850,11 +3850,11 @@ static int htx_apply_filter_to_sts_line(struct stream *s, struct channel *res, s
                return 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 */
        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;
                int len;
 
@@ -4847,7 +4847,7 @@ static int htx_stats_check_uri(struct stream *s, struct http_txn *txn, struct pr
                return 0;
 
        htx = htxbuf(&s->req.buf);
-       sl = http_find_stline(htx);
+       sl = http_get_stline(htx);
        uri = htx_sl_req_uri(sl);
 
        /* check URI size */
@@ -4890,7 +4890,7 @@ static int htx_handle_stats(struct stream *s, struct channel *req)
                appctx->ctx.stats.flags |= STAT_CHUNKED;
 
        htx = htxbuf(&req->buf);
-       sl = http_find_stline(htx);
+       sl = http_get_stline(htx);
        lookup = HTX_SL_REQ_UPTR(sl) + uri_auth->uri_len;
        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 */
        htx = htxbuf(&req->buf);
-       sl = http_find_stline(htx);
+       sl = http_get_stline(htx);
        path = http_get_path(htx_sl_req_uri(sl));
        if (!path.ptr)
                return;
index de7f8566726ff75ebb2357c9cde8f9183cdc53a5..7d9a8a3a7757be17d95912f81bacf3fd209eb604 100644 (file)
@@ -277,7 +277,7 @@ static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interfac
        if (IS_HTX_STRM(si_strm(si))) {
                struct channel *req = si_oc(si);
                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;
        }
index 071a7653605ff72f6cf5791eab7f00f5c62fdf69..b12d50bc3842933a8002876e9f4cd68c9ac0a1dc 100644 (file)
@@ -1305,7 +1305,7 @@ int si_cs_recv(struct conn_stream *cs)
 
                        htx = htxbuf(&ic->buf);
                        if (htx) {
-                               sl = http_find_stline(htx);
+                               sl = http_get_stline(htx);
                                if (sl && l7_status_match(si_strm(si)->be,
                                    sl->info.res.status)) {
                                        /* If we got a status for which we would