pgbackrest.git / summary / log / commit / refs

commit    078df66e2c66ea992c423ffc92a789a4f036b622
Author:   David Steele <david@pgmasters.net>
Date:     Sat Mar 16 08:51:37 2019 +0000

    Add httpHeaderDup().
    
    Allow duplication of headers and updating of redactions.


doc/xml/release.xml | 4 ++++ src/common/io/http/header.c | 33 ++++++++++++++++++++++++++++++++- src/common/io/http/header.h | 1 + test/src/module/common/ioHttpTest.c | 10 ++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 5b2ea7580..667041a78 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -37,6 +37,10 @@ <p>Add <id>CIFS</id> storage driver.</p> </release-item> + <release-item> + <p>Add <code>httpHeaderDup()</code>.</p> + </release-item> + <release-item> <p>Make <code>strLstDup()</code> null-tolerant.</p> </release-item> diff --git a/src/common/io/http/header.c b/src/common/io/http/header.c index e55b989d8..f5aaf2501 100644 --- a/src/common/io/http/header.c +++ b/src/common/io/http/header.c @@ -32,7 +32,7 @@ httpHeaderNew(const StringList *redactList) this = memNew(sizeof(HttpHeader)); this->memContext = MEM_CONTEXT_NEW(); - this->redactList = redactList; + this->redactList = strLstDup(redactList); this->kv = kvNew(); } MEM_CONTEXT_NEW_END(); @@ -40,6 +40,37 @@ httpHeaderNew(const StringList *redactList) FUNCTION_TEST_RETURN(this); } +/*********************************************************************************************************************************** +Duplicate object +***********************************************************************************************************************************/ +HttpHeader * +httpHeaderDup(const HttpHeader *header, const StringList *redactList) +{ + FUNCTION_TEST_BEGIN(); + FUNCTION_TEST_PARAM(HTTP_HEADER, header); + FUNCTION_TEST_PARAM(STRING_LIST, redactList); + FUNCTION_TEST_END(); + + HttpHeader *this = NULL; + + if (header != NULL) + { + + MEM_CONTEXT_NEW_BEGIN("HttpHeader") + { + // Allocate state and set context + this = memNew(sizeof(HttpHeader)); + this->memContext = MEM_CONTEXT_NEW(); + + this->redactList = redactList == NULL ? strLstDup(header->redactList) : strLstDup(redactList); + this->kv = kvDup(header->kv); + } + MEM_CONTEXT_NEW_END(); + } + + FUNCTION_TEST_RETURN(this); +} + /*********************************************************************************************************************************** Add a header ***********************************************************************************************************************************/ diff --git a/src/common/io/http/header.h b/src/common/io/http/header.h index d60e01c31..aef3c6d91 100644 --- a/src/common/io/http/header.h +++ b/src/common/io/http/header.h @@ -17,6 +17,7 @@ typedef struct HttpHeader HttpHeader; Constructor ***********************************************************************************************************************************/ HttpHeader *httpHeaderNew(const StringList *redactList); +HttpHeader *httpHeaderDup(const HttpHeader *header, const StringList *redactList); /*********************************************************************************************************************************** Functions diff --git a/test/src/module/common/ioHttpTest.c b/test/src/module/common/ioHttpTest.c index 7245ff33e..822ec7d84 100644 --- a/test/src/module/common/ioHttpTest.c +++ b/test/src/module/common/ioHttpTest.c @@ -326,6 +326,16 @@ testRun(void) httpHeaderAdd(header, strNew("public"), strNew("public-value")); TEST_RESULT_STR(strPtr(httpHeaderToLog(header)), "{public: 'public-value', secret: <redacted>}", "log output"); + + // Duplicate + // ------------------------------------------------------------------------------------------------------------------------- + TEST_RESULT_STR( + strPtr(httpHeaderToLog(httpHeaderDup(header, NULL))), + "{public: 'public-value', secret: <redacted>}", "dup and keep redactions"); + TEST_RESULT_STR( + strPtr(httpHeaderToLog(httpHeaderDup(header, strLstAddZ(strLstNew(), "public")))), + "{public: <redacted>, secret: 'secret-value'}", "dup and change redactions"); + TEST_RESULT_PTR(httpHeaderDup(NULL, NULL), NULL, "dup null http header"); } // ***************************************************************************************************************************** [parent: be670e25450a]