diff --git a/include/haproxy/http.h b/include/haproxy/http.h index f597ee4cd..73941336b 100644 --- a/include/haproxy/http.h +++ b/include/haproxy/http.h @@ -54,10 +54,10 @@ char *http_extract_cookie_value(char *hdr, const char *hdr_end, int http_parse_qvalue(const char *qvalue, const char **end); const char *http_find_url_param_pos(const char **chunks, const char* url_param_name, - size_t url_param_name_l, char delim); + size_t url_param_name_l, char delim, char insensitive); int http_find_next_url_param(const char **chunks, const char* url_param_name, size_t url_param_name_l, - const char **vstart, const char **vend, char delim); + const char **vstart, const char **vend, char delim, char insensitive); int http_parse_header(const struct ist hdr, struct ist *name, struct ist *value); int http_parse_stline(const struct ist line, struct ist *p1, struct ist *p2, struct ist *p3); diff --git a/src/http.c b/src/http.c index f55b69693..8aef755fd 100644 --- a/src/http.c +++ b/src/http.c @@ -995,7 +995,7 @@ int http_parse_qvalue(const char *qvalue, const char **end) */ const char *http_find_url_param_pos(const char **chunks, const char* url_param_name, size_t url_param_name_l, - char delim) + char delim, char insensitive) { const char *pos, *last, *equal; const char **bufs = chunks; @@ -1032,9 +1032,16 @@ const char *http_find_url_param_pos(const char **chunks, if (bufs[2] + l2 > bufs[3]) return NULL; - if (memcmp(pos, url_param_name, l1) == 0 && - memcmp(bufs[2], url_param_name+l1, l2) == 0) - return pos; + if (insensitive) { + if (strncasecmp(pos, url_param_name, l1) == 0 && + strncasecmp(bufs[2], url_param_name+l1, l2) == 0) + return pos; + } + else { + if (memcmp(pos, url_param_name, l1) == 0 && + memcmp(bufs[2], url_param_name+l1, l2) == 0) + return pos; + } /* Perform wrapping and jump the string who fail the comparison. */ bufs += 2; @@ -1042,9 +1049,14 @@ const char *http_find_url_param_pos(const char **chunks, last = bufs[1]; } else { - /* process a simple comparison. */ - if (memcmp(pos, url_param_name, url_param_name_l) == 0) - return pos; + /* process a simple comparison.*/ + if (insensitive) { + if (strncasecmp(pos, url_param_name, url_param_name_l) == 0) + return pos; + } else { + if (memcmp(pos, url_param_name, url_param_name_l) == 0) + return pos; + } pos += url_param_name_l + 1; if (fix_pointer_if_wrap(chunks, &pos)) last = bufs[2]; @@ -1078,7 +1090,7 @@ const char *http_find_url_param_pos(const char **chunks, */ int http_find_next_url_param(const char **chunks, const char* url_param_name, size_t url_param_name_l, - const char **vstart, const char **vend, char delim) + const char **vstart, const char **vend, char delim, char insensitive) { const char *arg_start, *qs_end; const char *value_start, *value_end; @@ -1089,7 +1101,7 @@ int http_find_next_url_param(const char **chunks, /* Looks for an argument name. */ arg_start = http_find_url_param_pos(chunks, url_param_name, url_param_name_l, - delim); + delim, insensitive); /* Check for wrapping. */ if (arg_start >= qs_end) qs_end = chunks[3]; diff --git a/src/http_fetch.c b/src/http_fetch.c index 732cfbbb1..270ef97d2 100644 --- a/src/http_fetch.c +++ b/src/http_fetch.c @@ -1833,14 +1833,14 @@ static int smp_fetch_cookie_val(const struct arg *args, struct sample *smp, cons * in ctx->a[1], and the optional second part in (ctx->a[2]..ctx->a[3]). The * pointers are updated for next iteration before leaving. */ -static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private) +static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private, char insensitive) { const char *vstart, *vend; struct buffer *temp; const char **chunks = (const char **)smp->ctx.a; if (!http_find_next_url_param(chunks, name, name_len, - &vstart, &vend, delim)) + &vstart, &vend, delim, insensitive)) return 0; /* Create sample. If the value is contiguous, return the pointer as CONST, @@ -1926,7 +1926,7 @@ static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const */ } - return smp_fetch_param(delim, name, name_len, args, smp, kw, private); + return smp_fetch_param(delim, name, name_len, args, smp, kw, private, 0); } /* This function iterates over each parameter of the body. This requires @@ -1984,7 +1984,7 @@ static int smp_fetch_body_param(const struct arg *args, struct sample *smp, cons } - return smp_fetch_param('&', name, name_len, args, smp, kw, private); + return smp_fetch_param('&', name, name_len, args, smp, kw, private, 0); } /* Return the signed integer value for the specified url parameter (see url_param