diff --git a/include/haproxy/h1_htx.h b/include/haproxy/h1_htx.h index 482997caa..a03f66e42 100644 --- a/include/haproxy/h1_htx.h +++ b/include/haproxy/h1_htx.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include int h1_parse_msg_hdrs(struct h1m *h1m, union h1_sl *h1sl, struct htx *dsthtx, struct buffer *srcbuf, size_t ofs, size_t max); @@ -37,6 +37,29 @@ int h1_parse_msg_data(struct h1m *h1m, struct htx **dsthtx, int h1_parse_msg_tlrs(struct h1m *h1m, struct htx *dsthtx, struct buffer *srcbuf, size_t ofs, size_t max); +/* Returns the URI of an HTX message in the most common format for a H1 peer. It + * is the path part of an absolute URI when the URI was normalized, ortherwise + * it is the whole URI, as received. Concretely, it is only a special case for + * URIs received from H2 clients, to be able to send a relative path the H1 + * servers. + */ +static inline struct ist h1_get_uri(const struct htx_sl *sl) +{ + struct ist uri; + + uri = htx_sl_req_uri(sl); + if (sl->flags & HTX_SL_F_NORMALIZED_URI) { + uri = http_get_path(uri); + if (unlikely(!uri.len)) { + if (sl->info.req.meth == HTTP_METH_OPTIONS) + uri = ist("*"); + else + uri = ist("/"); + } + } + return uri; +} + int h1_format_htx_reqline(const struct htx_sl *sl, struct buffer *chk); int h1_format_htx_stline(const struct htx_sl *sl, struct buffer *chk); int h1_format_htx_hdr(const struct ist n, const struct ist v, struct buffer *chk); diff --git a/src/h1_htx.c b/src/h1_htx.c index 1a1c89732..136bf461e 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -607,17 +607,7 @@ int h1_format_htx_reqline(const struct htx_sl *sl, struct buffer *chk) struct ist uri; size_t sz = chk->data; - uri = htx_sl_req_uri(sl); - if (sl->flags & HTX_SL_F_NORMALIZED_URI) { - uri = http_get_path(uri); - if (unlikely(!uri.len)) { - if (sl->info.req.meth == HTTP_METH_OPTIONS) - uri = ist("*"); - else - uri = ist("/"); - } - } - + uri = h1_get_uri(sl); if (!chunk_memcat(chk, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)) || !chunk_memcat(chk, " ", 1) || !chunk_memcat(chk, uri.ptr, uri.len) || diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 075a576de..73165c21d 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -1239,7 +1239,7 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst chunk_memcat(params->p, p.ptr, p.len); } if (!(params->mask & FCGI_SP_REQ_URI)) { - p = htx_sl_req_uri(sl); + p = h1_get_uri(sl); params->uri = ist2(b_tail(params->p), p.len); chunk_memcat(params->p, p.ptr, p.len); }