MINOR: http: use http uri parser for path
Replace http_get_path by the http_uri_parser API. The new functions is
renamed http_parse_path. Replace duplicated code for scheme and
authority parsing by invocations to http_parse_scheme/authority.
If no scheme is found for an URI detected as an absolute-uri/authority,
consider it to be an authority format : no path will be found. For an
absolute-uri or absolute-path, use the remaining of the string as the
path. A new http_uri_parser state is declared to mark the path parsing
as done.
diff --git a/src/http_ana.c b/src/http_ana.c
index da436e7..5eca741 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -206,9 +206,10 @@
if (unlikely(sess->fe->monitor_uri_len != 0)) {
const struct ist monitor_uri = ist2(sess->fe->monitor_uri,
sess->fe->monitor_uri_len);
+ struct http_uri_parser parser = http_uri_parser_init(htx_sl_req_uri(sl));
if ((istptr(monitor_uri)[0] == '/' &&
- isteq(http_get_path(htx_sl_req_uri(sl)), monitor_uri)) ||
+ isteq(http_parse_path(&parser), monitor_uri)) ||
isteq(htx_sl_req_uri(sl), monitor_uri)) {
/*
* We have found the monitor URI
@@ -622,6 +623,7 @@
if ((s->be->options & PR_O_HTTP_PROXY) && !(s->flags & SF_ADDR_SET)) {
struct htx_sl *sl;
struct ist uri, path;
+ struct http_uri_parser parser = http_uri_parser_init(uri);
if (!sockaddr_alloc(&s->target_addr, NULL, 0)) {
if (!(s->flags & SF_ERR_MASK))
@@ -630,7 +632,7 @@
}
sl = http_get_stline(htx);
uri = htx_sl_req_uri(sl);
- path = http_get_path(uri);
+ path = http_parse_path(&parser);
if (url2sa(uri.ptr, uri.len - path.len, s->target_addr, NULL) == -1)
goto return_bad_req;
@@ -2409,6 +2411,7 @@
case REDIRECT_TYPE_SCHEME: {
struct http_hdr_ctx ctx;
struct ist path, host;
+ struct http_uri_parser parser;
host = ist("");
ctx.blk = NULL;
@@ -2416,7 +2419,8 @@
host = ctx.value;
sl = http_get_stline(htx);
- path = http_get_path(htx_sl_req_uri(sl));
+ parser = http_uri_parser_init(htx_sl_req_uri(sl));
+ path = http_parse_path(&parser);
/* build message using path */
if (isttest(path)) {
if (rule->flags & REDIRECT_FLAG_DROP_QS) {
@@ -2462,9 +2466,11 @@
case REDIRECT_TYPE_PREFIX: {
struct ist path;
+ struct http_uri_parser parser;
sl = http_get_stline(htx);
- path = http_get_path(htx_sl_req_uri(sl));
+ parser = http_uri_parser_init(htx_sl_req_uri(sl));
+ path = http_parse_path(&parser);
/* build message using path */
if (isttest(path)) {
if (rule->flags & REDIRECT_FLAG_DROP_QS) {
@@ -3858,8 +3864,10 @@
htx = htxbuf(&s->req.buf);
sl = http_get_stline(htx);
uri = htx_sl_req_uri(sl);
- if (*uri_auth->uri_prefix == '/')
- uri = http_get_path(uri);
+ if (*uri_auth->uri_prefix == '/') {
+ struct http_uri_parser parser = http_uri_parser_init(uri);
+ uri = http_parse_path(&parser);
+ }
/* check URI size */
if (uri_auth->uri_len > uri.len)
@@ -4173,6 +4181,7 @@
struct htx_sl *sl;
struct ist path, location;
unsigned int flags;
+ struct http_uri_parser parser;
/*
* Create the location
@@ -4190,7 +4199,8 @@
/* 2: add the request Path */
htx = htxbuf(&req->buf);
sl = http_get_stline(htx);
- path = http_get_path(htx_sl_req_uri(sl));
+ parser = http_uri_parser_init(htx_sl_req_uri(sl));
+ path = http_parse_path(&parser);
if (!isttest(path))
return;