This is an automated email from the ASF dual-hosted git repository.
rrm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 3cbd6e1 Include start line of HTTP messages in xdebug probe output.
3cbd6e1 is described below
commit 3cbd6e14d2dd4fa8f13b866b935f3e4f93e607cc
Author: Walter Karas <[email protected]>
AuthorDate: Thu Mar 12 13:42:48 2020 -0500
Include start line of HTTP messages in xdebug probe output.
---
plugins/xdebug/xdebug_headers.cc | 144 +++++++++++++--------
.../gold_tests/pluginTest/xdebug/x_remap/out.gold | 72 ++++++++---
2 files changed, 146 insertions(+), 70 deletions(-)
diff --git a/plugins/xdebug/xdebug_headers.cc b/plugins/xdebug/xdebug_headers.cc
index aef6871..003658f 100644
--- a/plugins/xdebug/xdebug_headers.cc
+++ b/plugins/xdebug/xdebug_headers.cc
@@ -28,44 +28,88 @@
#define DEBUG_TAG_LOG_HEADERS "xdebug.headers"
-std::string_view
-escape_char_for_json(char const &c, bool &parsing_key)
+class EscapeCharForJson
{
- switch (c) {
- case '\'':
- return {"\\\'"};
- case '"':
- return {"\\\""};
- case '\\':
- return {"\\\\"};
- case '\b':
- return {"\\b"};
- case '\f':
- return {"\\f"};
- case '\t':
- return {"\\t"};
-
- // Special header reformatting
- case '\r':
- return {""};
- case '\n':
- parsing_key = true;
- return {"',\r\n\t'"}; // replace new line with pair delimiter
- case ':':
- if (parsing_key) {
- return {"' : "}; // replace colon after key with quote + colon
+public:
+ std::string_view
+ operator()(char const &c)
+ {
+ if ((_state != IN_VALUE) && ((' ' == c) || ('\t' == c))) {
+ return {""};
}
- return {":"};
- case ' ':
- if (parsing_key) {
- parsing_key = false;
- return {"'"}; // replace first space after the key to be a quote
+ if ((IN_NAME == _state) && (':' == c)) {
+ _state = BEFORE_VALUE;
+ return {"' : '"};
+ }
+ if ('\r' == c) {
+ return {""};
+ }
+ if ('\n' == c) {
+ std::string_view result{_after_value()};
+
+ if (BEFORE_NAME == _state) {
+ return {""};
+ } else if (BEFORE_VALUE == _state) {
+ // Failsafe -- missing value -- this should never happen.
+ result = _missing_value();
+ }
+ _state = BEFORE_NAME;
+ return result;
+ }
+ if (BEFORE_NAME == _state) {
+ _state = IN_NAME;
+ } else if (BEFORE_VALUE == _state) {
+ _state = IN_VALUE;
+ }
+ switch (c) {
+ case '\'':
+ return {"\\\'"};
+ case '"':
+ return {"\\\""};
+ case '\\':
+ return {"\\\\"};
+ case '\b':
+ return {"\\b"};
+ case '\f':
+ return {"\\f"};
+ case '\t':
+ return {"\\t"};
+ default:
+ return {&c, 1};
}
- return {" "};
- default:
- return {&c, 1};
}
-}
+
+ // After last header line, back up and throw away everything but the closing
quote.
+ //
+ static std::size_t
+ backup()
+ {
+ return _after_value().size() - 1;
+ }
+
+private:
+ static std::string_view
+ _missing_value()
+ {
+ return {"' : '',\n\t'"};
+ }
+
+ static std::string_view
+ _after_name()
+ {
+ return {_missing_value().data(), 5};
+ }
+
+ static std::string_view
+ _after_value()
+ {
+ return {_missing_value().data() + 5, 5};
+ }
+
+ enum _State { BEFORE_NAME, IN_NAME, BEFORE_VALUE, IN_VALUE };
+
+ _State _state{BEFORE_VALUE};
+};
///////////////////////////////////////////////////////////////////////////
// Dump a header on stderr, useful together with TSDebug().
@@ -77,37 +121,33 @@ print_headers(TSHttpTxn txn, TSMBuffer bufp, TSMLoc
hdr_loc, std::stringstream &
TSIOBufferBlock block;
const char *block_start;
int64_t block_avail;
- bool parsing_key = true;
- size_t print_rewind = ss.str().length();
- output_buffer = TSIOBufferCreate();
- reader = TSIOBufferReaderAlloc(output_buffer);
+ EscapeCharForJson escape_char_for_json;
+ output_buffer = TSIOBufferCreate();
+ reader = TSIOBufferReaderAlloc(output_buffer);
- ss << "\t'";
- /* This will print just MIMEFields and not the http request line */
- TSMimeHdrPrint(bufp, hdr_loc, output_buffer);
+ ss << "\t'Start-Line' : '";
+
+ // Print all message header lines.
+ TSHttpHdrPrint(bufp, hdr_loc, output_buffer);
/* We need to loop over all the buffer blocks, there can be more than 1 */
block = TSIOBufferReaderStart(reader);
do {
block_start = TSIOBufferBlockReadStart(block, reader, &block_avail);
for (const char *c = block_start; c < block_start + block_avail; ++c) {
- bool was_parsing_key = parsing_key;
- ss << escape_char_for_json(*c, parsing_key);
- if (parsing_key && !was_parsing_key) {
- print_rewind = ss.str().length() - 1;
- }
+ ss << escape_char_for_json(*c);
}
TSIOBufferReaderConsume(reader, block_avail);
block = TSIOBufferReaderStart(reader);
} while (block && block_avail != 0);
- ss.seekp(print_rewind);
+ ss.seekp(-escape_char_for_json.backup(), std::ios_base::end);
/* Free up the TSIOBuffer that we used to print out the header */
TSIOBufferReaderFree(reader);
TSIOBufferDestroy(output_buffer);
- TSDebug(DEBUG_TAG_LOG_HEADERS, "%s", ss.str().c_str());
+ TSDebug(DEBUG_TAG_LOG_HEADERS, "%.*s", static_cast<int>(ss.tellp()),
ss.str().data());
}
void
@@ -128,13 +168,13 @@ print_request_headers(TSHttpTxn txn, std::stringstream
&output)
if (TSHttpTxnClientReqGet(txn, &buf_c, &hdr_loc) == TS_SUCCESS) {
output << "{'type':'request', 'side':'client', 'headers': {\n";
print_headers(txn, buf_c, hdr_loc, output);
- output << "}}";
+ output << "\n\t}}";
TSHandleMLocRelease(buf_c, TS_NULL_MLOC, hdr_loc);
}
if (TSHttpTxnServerReqGet(txn, &buf_s, &hdr_loc) == TS_SUCCESS) {
output << ",{'type':'request', 'side':'server', 'headers': {\n";
print_headers(txn, buf_s, hdr_loc, output);
- output << "}}";
+ output << "\n\t}}";
TSHandleMLocRelease(buf_s, TS_NULL_MLOC, hdr_loc);
}
}
@@ -147,13 +187,13 @@ print_response_headers(TSHttpTxn txn, std::stringstream
&output)
if (TSHttpTxnServerRespGet(txn, &buf_s, &hdr_loc) == TS_SUCCESS) {
output << "{'type':'response', 'side':'server', 'headers': {\n";
print_headers(txn, buf_s, hdr_loc, output);
- output << "}},";
+ output << "\n\t}},";
TSHandleMLocRelease(buf_s, TS_NULL_MLOC, hdr_loc);
}
if (TSHttpTxnClientRespGet(txn, &buf_c, &hdr_loc) == TS_SUCCESS) {
output << "{'type':'response', 'side':'client', 'headers': {\n";
print_headers(txn, buf_c, hdr_loc, output);
- output << "}}";
+ output << "\n\t}}";
TSHandleMLocRelease(buf_c, TS_NULL_MLOC, hdr_loc);
}
}
diff --git a/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
b/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
index f9b673e..6712754 100644
--- a/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
+++ b/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
@@ -37,9 +37,11 @@ X-Remap: from=http://one/, to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'Client-ip' : '127.0.0.1',
'X-Forwarded-For' : '127.0.0.1',
@@ -54,15 +56,17 @@ X-Remap: from=http://one/, to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://one/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://one/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -80,9 +84,11 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'Client-ip' : '127.0.0.1',
'X-Forwarded-For' : '127.0.0.1',
@@ -97,15 +103,17 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -123,9 +131,11 @@ X-Remap: from=http://three[0-9]+/,
to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'Client-ip' : '127.0.0.1',
'X-Forwarded-For' : '127.0.0.1',
@@ -140,15 +150,17 @@ X-Remap: from=http://three[0-9]+/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://three[0-9]+/,
to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://three[0-9]+/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -166,9 +178,11 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/not_there HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /not_there HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'Client-ip' : '127.0.0.1',
'X-Forwarded-For' : '127.0.0.1',
@@ -183,16 +197,18 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 404 Not Found',
'Server' : 'MicroServer',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 404 Not Found',
'Server' : 'ATS/``
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -210,10 +226,12 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'X-Debug' : 'X-Remap, fwd, Probe',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'X-Debug' : 'X-Remap, fwd, Probe',
'Client-ip' : '127.0.0.1',
@@ -229,15 +247,17 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -255,9 +275,11 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'Client-ip' : '127.0.0.1',
'X-Forwarded-For' : '127.0.0.1',
@@ -272,15 +294,17 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -298,10 +322,12 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'X-Debug' : 'X-Remap, fwd=0, Probe',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'X-Debug' : 'X-Remap, fwd=0, Probe',
'Client-ip' : '127.0.0.1',
@@ -317,15 +343,17 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -343,10 +371,12 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'X-Debug' : 'PROBE, X-Remap, fwd=999998',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'X-Debug' : 'PROBE, X-Remap, fwd=999998',
'Client-ip' : '127.0.0.1',
@@ -362,15 +392,17 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}
@@ -388,9 +420,11 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
``
{'xDebugProbeAt' : '``
'captured':[{'type':'request', 'side':'client', 'headers': {
+ 'Start-Line' : 'GET http://127.0.0.1:SERVER_PORT/argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
- 'Connection' : 'close',
+ 'Connection' : 'close'
}},{'type':'request', 'side':'server', 'headers': {
+ 'Start-Line' : 'GET /argh HTTP/1.1',
'Host' : '127.0.0.1:SERVER_PORT',
'Client-ip' : '127.0.0.1',
'X-Forwarded-For' : '127.0.0.1',
@@ -405,15 +439,17 @@ X-Remap: from=http://two/,
to=http://127.0.0.1:SERVER_PORT/
{'xDebugProbeAt' : '``
'captured':[{'type':'response', 'side':'server', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Connection' : 'close',
'Date' : '``
}},{'type':'response', 'side':'client', 'headers': {
+ 'Start-Line' : 'HTTP/1.1 200 OK',
'Date' : '``
'Age' : '``
'Transfer-Encoding' : 'chunked',
'Connection' : 'close',
'Server' : 'ATS/``
- 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/',
+ 'X-Remap' : 'from=http://two/, to=http://127.0.0.1:SERVER_PORT/'
}}
]
}