mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-24 20:31:00 +01:00
MINOR: http: optimize capture.req.method and capture.req.uri
Useless strncpy were done in those two sample fetches, the "struct chunk" allows us to dump the specified len. The encode_string() in capture.req.uri was judged inappropriate and was deleted. The return type was fixed to SMP_T_CSTR.
This commit is contained in:
parent
a23ee3a2ea
commit
96a7785429
@ -9778,26 +9778,21 @@ smp_fetch_capture_req_method(struct proxy *px, struct session *l4, void *l7, uns
|
|||||||
{
|
{
|
||||||
struct chunk *temp;
|
struct chunk *temp;
|
||||||
struct http_txn *txn = l7;
|
struct http_txn *txn = l7;
|
||||||
char *spc;
|
char *ptr;
|
||||||
int len;
|
|
||||||
|
|
||||||
if (!txn->uri)
|
if (!txn->uri)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
spc = strchr(txn->uri, ' '); /* first space before URI */
|
ptr = txn->uri;
|
||||||
if (likely(spc))
|
|
||||||
len = spc - txn->uri;
|
while (*ptr != ' ' && *ptr != '\0') /* find first space */
|
||||||
else
|
ptr++;
|
||||||
len = strlen(txn->uri);
|
|
||||||
|
|
||||||
temp = get_trash_chunk();
|
temp = get_trash_chunk();
|
||||||
len = MIN(len, temp->size - 1);
|
temp->str = txn->uri;
|
||||||
strncpy(temp->str, txn->uri, len);
|
temp->len = ptr - txn->uri;
|
||||||
temp->str[len] = '\0';
|
|
||||||
|
|
||||||
smp->data.str = *temp;
|
smp->data.str = *temp;
|
||||||
smp->data.str.len = len;
|
smp->type = SMP_T_CSTR;
|
||||||
smp->type = SMP_T_STR;
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -9811,33 +9806,30 @@ smp_fetch_capture_req_uri(struct proxy *px, struct session *l4, void *l7, unsign
|
|||||||
struct chunk *temp;
|
struct chunk *temp;
|
||||||
struct http_txn *txn = l7;
|
struct http_txn *txn = l7;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
char *ret;
|
|
||||||
|
|
||||||
if (!txn->uri)
|
if (!txn->uri)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ptr = txn->uri;
|
ptr = txn->uri;
|
||||||
|
|
||||||
while (*ptr != ' ' && *ptr != '\0') /* find first space */
|
while (*ptr != ' ' && *ptr != '\0') /* find first space */
|
||||||
ptr++;
|
ptr++;
|
||||||
|
|
||||||
if (!*ptr)
|
if (!*ptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ptr++; /* skip the space */
|
ptr++; /* skip the space */
|
||||||
|
|
||||||
temp = get_trash_chunk();
|
temp = get_trash_chunk();
|
||||||
ret = encode_string(temp->str, temp->str + temp->size, '#', url_encode_map, ptr);
|
ptr = temp->str = http_get_path_from_string(ptr);
|
||||||
if (ret == NULL || *ret != '\0')
|
|
||||||
return 0;
|
|
||||||
ptr = temp->str = http_get_path_from_string(temp->str);
|
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
return 0;
|
return 0;
|
||||||
while (*ptr != ' ' && *ptr != '\0') /* find space after URI */
|
while (*ptr != ' ' && *ptr != '\0') /* find space after URI */
|
||||||
ptr++;
|
ptr++;
|
||||||
*ptr = '\0';
|
|
||||||
|
|
||||||
smp->data.str = *temp;
|
smp->data.str = *temp;
|
||||||
smp->data.str.len = strlen(smp->data.str.str);
|
smp->data.str.len = ptr - temp->str;
|
||||||
smp->type = SMP_T_STR;
|
smp->type = SMP_T_CSTR;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user