MEDIUM: http_fetch: Remove code relying on HTTP legacy mode

Since the legacy HTTP mode is disbabled, all HTTP sample fetches work on HTX
streams. So it is safe to remove all code relying on HTTP legacy mode. Among
other things, the function smp_prefetch_http() was removed with the associated
macros CHECK_HTTP_MESSAGE_FIRST() and CHECK_HTTP_MESSAGE_FIRST_PERM().
This commit is contained in:
Christopher Faulet 2019-07-15 14:36:03 +02:00
parent 9a7e8ce4eb
commit 6d1dd46917
5 changed files with 662 additions and 1854 deletions

View File

@ -23,25 +23,12 @@
#define _PROTO_HTTP_FETCH_H
#include <common/config.h>
#include <common/mini-clist.h>
#include <types/action.h>
#include <types/proxy.h>
#include <common/htx.h>
#include <types/arg.h>
#include <types/channel.h>
#include <types/sample.h>
/* Note: these functions *do* modify the sample. Even in case of success, at
* least the type and uint value are modified.
*/
#define CHECK_HTTP_MESSAGE_FIRST(chn) \
do { int r = smp_prefetch_http(smp->px, smp->strm, smp->opt, (chn), smp, 1); if (r <= 0) return r; } while (0)
#define CHECK_HTTP_MESSAGE_FIRST_PERM(chn) \
do { int r = smp_prefetch_http(smp->px, smp->strm, smp->opt, (chn), smp, 0); if (r <= 0) return r; } while (0)
int smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt,
struct channel *chn, struct sample *smp, int req_vol);
struct htx;
struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol);
int val_hdr(struct arg *arg, char **err_msg);

View File

@ -227,17 +227,13 @@ static void _51d_retrieve_cache_entry(struct sample *smp, struct lru64 *lru)
*/
static void _51d_set_headers(struct sample *smp, fiftyoneDegreesWorkset *ws)
{
int i;
ws->importantHeadersCount = 0;
if (smp->px->options2 & PR_O2_USE_HTX) {
/* HTX version */
struct channel *chn;
struct htx *htx;
struct http_hdr_ctx ctx;
struct ist name;
struct channel *chn;
int i;
ws->importantHeadersCount = 0;
chn = (smp->strm ? &smp->strm->req : NULL);
// No need to null check as this has already been carried out in the
@ -256,36 +252,6 @@ static void _51d_set_headers(struct sample *smp, fiftyoneDegreesWorkset *ws)
ws->importantHeadersCount++;
}
}
}
else {
/* Legacy Version */
struct hdr_idx *idx;
struct hdr_ctx ctx;
const struct http_msg *msg;
idx = &smp->strm->txn->hdr_idx;
msg = &smp->strm->txn->req;
for (i = 0; i < global_51degrees.header_count; i++) {
ctx.idx = 0;
if (http_find_full_header2((global_51degrees.header_names + i)->area,
(global_51degrees.header_names + i)->data,
#ifndef BUF_NULL
msg->chn->buf->p,
#else
ci_head(msg->chn),
#endif
idx,
&ctx) == 1) {
ws->importantHeaders[ws->importantHeadersCount].header = ws->dataSet->httpHeaders + i;
ws->importantHeaders[ws->importantHeadersCount].headerValue = ctx.line + ctx.val;
ws->importantHeaders[ws->importantHeadersCount].headerValueLength = ctx.vlen;
ws->importantHeadersCount++;
}
}
}
}
#endif
@ -299,17 +265,13 @@ static void _51d_init_device_offsets(fiftyoneDegreesDeviceOffsets *offsets) {
static void _51d_set_device_offsets(struct sample *smp, fiftyoneDegreesDeviceOffsets *offsets)
{
int i;
offsets->size = 0;
if (smp->px->options2 & PR_O2_USE_HTX) {
/* HTX version */
struct channel *chn;
struct htx *htx;
struct http_hdr_ctx ctx;
struct ist name;
struct channel *chn;
int i;
offsets->size = 0;
chn = (smp->strm ? &smp->strm->req : NULL);
// No need to null check as this has already been carried out in the
@ -329,34 +291,6 @@ static void _51d_set_device_offsets(struct sample *smp, fiftyoneDegreesDeviceOff
}
}
else {
/* Legacy Version */
struct hdr_idx *idx;
struct hdr_ctx ctx;
const struct http_msg *msg;
idx = &smp->strm->txn->hdr_idx;
msg = &smp->strm->txn->req;
for (i = 0; i < global_51degrees.header_count; i++) {
ctx.idx = 0;
if (http_find_full_header2((global_51degrees.header_names + i)->area,
(global_51degrees.header_names + i)->data,
#ifndef BUF_NULL
msg->chn->buf->p,
#else
ci_head(msg->chn),
#endif
idx,
&ctx) == 1) {
(offsets->firstOffset + offsets->size)->httpHeaderOffset = *(global_51degrees.header_offsets + i);
(offsets->firstOffset + offsets->size)->deviceOffset = fiftyoneDegreesGetDeviceOffset(&global_51degrees.data_set, ctx.line + ctx.val);
offsets->size++;
}
}
}
}
#endif
#ifdef FIFTYONEDEGREES_H_PATTERN_INCLUDED
@ -472,18 +406,13 @@ static int _51d_fetch(const struct arg *args, struct sample *smp, const char *kw
#endif
struct channel *chn;
chn = (smp->strm ? &smp->strm->req : NULL);
struct htx *htx;
if (smp->px->options2 & PR_O2_USE_HTX) {
/* HTX version */
struct htx *htx = smp_prefetch_htx(smp, chn, 1);
if (!htx) {
chn = (smp->strm ? &smp->strm->req : NULL);
htx = smp_prefetch_htx(smp, chn, 1);
if (!htx)
return 0;
}
} else {
/* Legacy version */
CHECK_HTTP_MESSAGE_FIRST(chn);
}
/*
* Data type has to be reset to ensure the string output is processed
* correctly.

View File

@ -291,6 +291,8 @@ static int da_haproxy_fetch(const struct arg *args, struct sample *smp, const ch
da_deviceinfo_t devinfo;
da_status_t status;
struct channel *chn;
struct htx *htx;
struct htx_blk *blk;
char vbuf[DA_MAX_HEADERS][1024] = {{ 0 }};
int i, nbh = 0;
@ -299,13 +301,9 @@ static int da_haproxy_fetch(const struct arg *args, struct sample *smp, const ch
}
chn = (smp->strm ? &smp->strm->req : NULL);
/* HTX Mode check */
if (smp->px->options2 & PR_O2_USE_HTX) {
struct htx_blk *blk;
struct htx *htx = smp_prefetch_htx(smp, chn, 1);
if (!htx) {
htx = smp_prefetch_htx(smp, chn, 1);
if (!htx)
return 0;
}
i = 0;
for (blk = htx_get_first_blk(htx); nbh < DA_MAX_HEADERS && blk; blk = htx_get_next_blk(htx, blk)) {
@ -377,75 +375,6 @@ static int da_haproxy_fetch(const struct arg *args, struct sample *smp, const ch
ev[nbh].value = vbuf[nbh];
++ nbh;
}
} else {
struct hdr_idx *hidx;
struct hdr_ctx hctx;
const struct http_msg *hmsg;
CHECK_HTTP_MESSAGE_FIRST(chn);
smp->data.type = SMP_T_STR;
/**
* Here we go through the whole list of headers from start
* they will be filtered via the DeviceAtlas API itself
*/
hctx.idx = 0;
hidx = &smp->strm->txn->hdr_idx;
hmsg = &smp->strm->txn->req;
while (http_find_next_header(ci_head(hmsg->chn), hidx, &hctx) == 1 &&
nbh < DA_MAX_HEADERS) {
char *pval;
size_t vlen;
da_evidence_id_t evid = -1;
char hbuf[24] = { 0 };
/* The HTTP headers used by the DeviceAtlas API are not longer */
if (hctx.del >= sizeof(hbuf) || hctx.del <= 0 || hctx.vlen <= 0) {
continue;
}
vlen = hctx.vlen;
memcpy(hbuf, hctx.line, hctx.del);
hbuf[hctx.del] = 0;
pval = (hctx.line + hctx.val);
if (strcmp(hbuf, "Accept-Language") == 0) {
evid = da_atlas_accept_language_evidence_id(&global_deviceatlas.
atlas);
} else if (strcmp(hbuf, "Cookie") == 0) {
char *p, *eval;
size_t pl;
eval = pval + hctx.vlen;
/**
* The cookie value, if it exists, is located between the current header's
* value position and the next one
*/
if (http_extract_cookie_value(pval, eval, global_deviceatlas.cookiename,
global_deviceatlas.cookienamelen, 1, &p, &pl) == NULL) {
continue;
}
vlen = (size_t)pl;
pval = p;
evid = da_atlas_clientprop_evidence_id(&global_deviceatlas.atlas);
} else {
evid = da_atlas_header_evidence_id(&global_deviceatlas.atlas,
hbuf);
}
if (evid == -1) {
continue;
}
i = vlen > sizeof(vbuf[nbh]) ? sizeof(vbuf[nbh]) : vlen;
memcpy(vbuf[nbh], pval, i - 1);
vbuf[nbh][i - 1] = 0;
ev[nbh].key = evid;
ev[nbh].value = vbuf[nbh];
++ nbh;
}
}
status = da_searchv(&global_deviceatlas.atlas, &devinfo,
ev, nbh);

File diff suppressed because it is too large Load Diff

View File

@ -431,23 +431,14 @@ static int ha_wurfl_get_all(const struct arg *args, struct sample *smp, const ch
wurfl_information_t *wi;
ha_wurfl_header_t wh;
struct channel *chn;
struct htx *htx;
ha_wurfl_log("WURFL: starting ha_wurfl_get_all\n");
chn = (smp->strm ? &smp->strm->req : NULL);
if (smp->px->options2 & PR_O2_USE_HTX) {
/* HTX version */
struct htx *htx = smp_prefetch_htx(smp, chn, 1);
if (!htx) {
htx = smp_prefetch_htx(smp, chn, 1);
if (!htx)
return 0;
}
} else {
/* Legacy version */
CHECK_HTTP_MESSAGE_FIRST(chn);
}
wh.wsmp = smp;
@ -526,23 +517,14 @@ static int ha_wurfl_get(const struct arg *args, struct sample *smp, const char *
ha_wurfl_header_t wh;
int i = 0;
struct channel *chn;
struct htx *htx;
ha_wurfl_log("WURFL: starting ha_wurfl_get\n");
chn = (smp->strm ? &smp->strm->req : NULL);
if (smp->px->options2 & PR_O2_USE_HTX) {
/* HTX version */
struct htx *htx = smp_prefetch_htx(smp, chn, 1);
if (!htx) {
htx = smp_prefetch_htx(smp, chn, 1);
if (!htx)
return 0;
}
} else {
/* Legacy version */
CHECK_HTTP_MESSAGE_FIRST(chn);
}
wh.wsmp = smp;
@ -741,17 +723,14 @@ static const char *ha_wurfl_retrieve_header(const char *header_name, const void
{
struct sample *smp;
struct channel *chn;
struct htx *htx;
struct http_hdr_ctx ctx;
struct ist name;
int header_len = HA_WURFL_MAX_HEADER_LENGTH;
smp = ((ha_wurfl_header_t *)wh)->wsmp;
chn = (smp->strm ? &smp->strm->req : NULL);
if (smp->px->options2 & PR_O2_USE_HTX) {
/* HTX version */
struct htx *htx;
struct http_hdr_ctx ctx;
struct ist name;
ha_wurfl_log("WURFL: retrieve header (HTX) request [%s]\n", header_name);
//the header is searched from the beginning
@ -779,39 +758,6 @@ static const char *ha_wurfl_retrieve_header(const char *header_name, const void
strncpy(((ha_wurfl_header_t *)wh)->header_value, ctx.value.ptr, header_len);
} else {
/* Legacy version */
struct http_txn *txn;
struct hdr_idx *idx;
struct hdr_ctx ctx;
int res;
ha_wurfl_log("WURFL: retrieve header (legacy) request [%s]\n", header_name);
// We could skip this chek since ha_wurfl_retrieve_header is called from inside
// ha_wurfl_get()/ha_wurfl_get_all() that already perform the same check
// We choose to keep it in case ha_wurfl_retrieve_header will be called directly
// This is a version of CHECK_HTTP_MESSAGE_FIRST(chn) which returns NULL in case of error
res = smp_prefetch_http(smp->px, smp->strm, smp->opt, (chn), smp, 1);
if (res <= 0) {
return NULL;
}
txn = smp->strm->txn;
idx = &txn->hdr_idx;
ctx.idx = 0;
if (http_find_full_header2(header_name, strlen(header_name), ci_head(chn), idx, &ctx) == 0)
return NULL;
if (header_len > ctx.vlen)
header_len = ctx.vlen;
strncpy(((ha_wurfl_header_t *)wh)->header_value, ctx.line + ctx.val, header_len);
}
((ha_wurfl_header_t *)wh)->header_value[header_len] = '\0';
ha_wurfl_log("WURFL: retrieve header request returns [%s]\n", ((ha_wurfl_header_t *)wh)->header_value);