Skip to content

Commit b8fb2bb

Browse files
committed
MINOR: added possibility to change HTTP headers that are sent to mirror URL
The function spoa_msg_arg_hdrs() has been added, which allows changing the type of the SPOE argument 'arg_hdrs' to a string (until now, that argument could only be binary). In this way, the use of the regsub() converter is enabled in that argument, so that it is now possible to change the HTTP headers that are sent to the mirror URL. For example, instead of: args arg_method=method arg_path=url arg_ver=req.ver arg_hdrs=req.hdrs_bin arg_body=req.body , the following can be used: args arg_method=method arg_path=url arg_ver=req.ver arg_hdrs=req.hdrs,regsub(foo,bar) arg_body=req.body Version of the program changed to v1.2.18.
1 parent 2cfa6c0 commit b8fb2bb

File tree

4 files changed

+94
-2
lines changed

4 files changed

+94
-2
lines changed

README

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ configuration file:
162162
# /path-to/haproxy -f haproxy.cfg
163163

164164

165+
Note related to SPOE configuration: in the 'spoe-message' section (in the
166+
given example, this section is called 'mirror') the 'args' keyword must always
167+
(and only) contain the following arguments (after the sign '=' there is a
168+
permitted argument type):
169+
170+
arg_method=STR arg_path=STR arg_ver=STR arg_hdrs=(BIN|STR) arg_body=BIN
171+
172+
'arg_hdrs' can have a binary (req.hdrs_bin) or string (req.hdrs) data type
173+
argument specified. In case we want to make some changes in the HTTP headers
174+
that are sent to the mirror URL, then we will use the string data type for
175+
that argument to which we can add the regsub() converter, as in the example:
176+
177+
.. arg_hdrs=req.hdrs,regsub(foo,bar)
178+
179+
165180
4. Known bugs and limitations
166181
------------------------------------------------------------------------
167182

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.17
1+
1.2.18

src/.build-counter

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2513
1+
2519

src/spoa-message.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,72 @@ static int spoa_msg_arg_hdrs_bin(struct spoe_frame *frame, const char *buf, cons
316316
}
317317

318318

319+
/***
320+
* NAME
321+
* spoa_msg_arg_hdrs -
322+
*
323+
* ARGUMENTS
324+
* frame -
325+
* buf -
326+
* end -
327+
* hdrs -
328+
*
329+
* DESCRIPTION
330+
* -
331+
*
332+
* RETURN VALUE
333+
* -
334+
*/
335+
static int spoa_msg_arg_hdrs(struct spoe_frame *frame, const char *buf, const char *end, struct list *hdrs)
336+
{
337+
struct buffer *hdr = NULL, *hdr_back;
338+
const char *ptr;
339+
int i, retval = FUNC_RET_OK;
340+
341+
DBG_FUNC(FW_PTR, "%p, %p, %p, %p", frame, buf, end, hdrs);
342+
343+
/* Build the HTTP headers. */
344+
for (i = 0; buf < end; i++) {
345+
/* Find end of the HTTP header (CRLF). */
346+
for (ptr = buf; ptr < end; ptr++)
347+
if (TEST_OR2(*ptr, '\r', '\n'))
348+
break;
349+
350+
/*
351+
* Can the HTTP header be empty?
352+
* In that case, this block is skipped.
353+
*/
354+
if (ptr != buf) {
355+
if (_NULL(hdr = buffer_alloc(cfg.max_frame_size, buf, ptr - buf, NULL)))
356+
break;
357+
358+
F_DBG(SPOA, frame, "header[%d]: <%.*s>", i, (int)hdr->len, hdr->ptr);
359+
360+
LIST_ADDQ(hdrs, &(hdr->list));
361+
}
362+
363+
/* Skip the end of the HTTP header (CRLF). */
364+
for (buf = ptr; buf < end; buf++)
365+
if (TEST_NAND2(*buf, '\r', '\n'))
366+
break;
367+
}
368+
369+
/* In the case of a fault, the allocated memory is released. */
370+
if (_ERROR(retval) || ((i > 0) && _NULL(hdr))) {
371+
buffer_ptr_free(&hdr);
372+
373+
list_for_each_entry_safe(hdr, hdr_back, hdrs, list) {
374+
LIST_DEL(&(hdr->list));
375+
buffer_ptr_free(&hdr);
376+
}
377+
378+
retval = FUNC_RET_ERROR;
379+
}
380+
381+
DBG_RETURN_INT(retval);
382+
}
383+
384+
319385
/***
320386
* NAME
321387
* spoa_msg_mirror -
@@ -373,6 +439,17 @@ int spoa_msg_mirror(struct spoe_frame *frame, const char **buf, const char *end)
373439
mir_ptr = &(mir->path);
374440
else if ((len == STR_SIZE(SPOE_MSG_ARG_VER)) && (memcmp(str, STR_ADDRSIZE(SPOE_MSG_ARG_VER)) == 0))
375441
mir_ptr = &(mir->version);
442+
else if ((len == STR_SIZE(SPOE_MSG_ARG_HDRS)) && (memcmp(str, STR_ADDRSIZE(SPOE_MSG_ARG_HDRS)) == 0)) {
443+
if (!LIST_ISEMPTY(&(mir->hdrs))) {
444+
f_log(frame, _E("arg[%d] '%.*s': Duplicated argument"), i, (int)len, str);
445+
446+
retval = FUNC_RET_ERROR;
447+
}
448+
else
449+
retval = spoa_msg_arg_hdrs(frame, data.chk.ptr, data.chk.ptr + data.chk.len - 1, &(mir->hdrs));
450+
451+
continue;
452+
}
376453
else {
377454
f_log(frame, _W("Unknown argument, ignored: '%.*s'"), (int)len, str);
378455

0 commit comments

Comments
 (0)