You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2022/12/15 19:43:18 UTC
[trafficserver] branch 9.2.x updated: Change Content-Type to text/plain if xdebug modifies response body (#9246)
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch 9.2.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/9.2.x by this push:
new f27cd8205 Change Content-Type to text/plain if xdebug modifies response body (#9246)
f27cd8205 is described below
commit f27cd82059fc8c2a2f84a96a12f7b89f17f4a667
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Thu Dec 15 10:06:15 2022 -0700
Change Content-Type to text/plain if xdebug modifies response body (#9246)
* Change Content-Type to text/plain if xdebug modifies response body
Co-authored-by: Bryan Call <bc...@apache.org>
* Fix indentation
Co-authored-by: Bryan Call <bc...@apache.org>
(cherry picked from commit eb5efe19e68e51db58a6320b4a99e3fc83336a14)
---
plugins/xdebug/xdebug.cc | 24 ++++++++++++++
.../gold_tests/pluginTest/xdebug/x_remap/out.gold | 37 ++++++++++++++++------
2 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/plugins/xdebug/xdebug.cc b/plugins/xdebug/xdebug.cc
index 6943871fc..331ae6eeb 100644
--- a/plugins/xdebug/xdebug.cc
+++ b/plugins/xdebug/xdebug.cc
@@ -400,6 +400,29 @@ InjectEffectiveURLHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
TSfree(strval.ptr);
}
+static void
+InjectOriginalContentTypeHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
+{
+ TSMLoc ct_field = TSMimeHdrFieldFind(buffer, hdr, TS_MIME_FIELD_CONTENT_TYPE, TS_MIME_LEN_CONTENT_TYPE);
+ if (TS_NULL_MLOC != ct_field) {
+ int original_content_type_len = 0;
+ const char *original_content_type = TSMimeHdrFieldValueStringGet(buffer, hdr, ct_field, -1, &original_content_type_len);
+ if (original_content_type != nullptr) {
+ TSMLoc dst = FindOrMakeHdrField(buffer, hdr, "X-Original-Content-Type", lengthof("X-Original-Content-Type"));
+ TSReleaseAssert(TS_NULL_MLOC != dst);
+ TSReleaseAssert(TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, -1 /* idx */, original_content_type,
+ original_content_type_len) == TS_SUCCESS);
+ }
+ } else {
+ if (TSMimeHdrFieldCreateNamed(buffer, hdr, TS_MIME_FIELD_CONTENT_TYPE, TS_MIME_LEN_CONTENT_TYPE, &ct_field) == TS_SUCCESS) {
+ TSReleaseAssert(TSMimeHdrFieldAppend(buffer, hdr, ct_field) == TS_SUCCESS);
+ }
+ }
+
+ TSMimeHdrFieldValuesClear(buffer, hdr, ct_field);
+ TSReleaseAssert(TSMimeHdrFieldValueStringSet(buffer, hdr, ct_field, -1, "text/plain", lengthof("text/plain")) == TS_SUCCESS);
+}
+
static void
InjectTxnUuidHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr)
{
@@ -519,6 +542,7 @@ XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void *edata)
}
if (xheaders & XHEADER_X_PROBE_HEADERS) {
+ InjectOriginalContentTypeHeader(txn, buffer, hdr);
BodyBuilder *data = AuxDataMgr::data(txn).body_builder.get();
TSDebug("xdebug_transform", "XInjectResponseHeaders(): client resp header ready");
if (data == nullptr) {
diff --git a/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold b/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
index f9f4ebef2..7cd12e1ec 100644
--- a/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
+++ b/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold
@@ -6,6 +6,7 @@ Cache-Control: no-store
Content-Type: text/html
Content-Language: en
X-Remap: from=Not-Found, to=Not-Found
+X-Original-Content-Type: text/html; charset=utf-8
Content-Length: 391
<HTML>
@@ -33,6 +34,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://one/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -66,7 +68,8 @@ X-Remap: from=http://one/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -80,6 +83,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -113,7 +117,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -127,6 +132,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://three[0-9]+/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -160,7 +166,8 @@ X-Remap: from=http://three[0-9]+/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -174,6 +181,7 @@ Age: ``
Transfer-Encoding: chunked
Connection: close
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -208,7 +216,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -222,6 +231,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -257,7 +267,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -271,6 +282,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -304,7 +316,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -318,6 +331,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -353,7 +367,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -367,6 +382,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -402,7 +418,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}
@@ -416,6 +433,7 @@ Transfer-Encoding: chunked
Connection: close
Server: ATS/``
X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
+Content-Type: text/plain
``
{'xDebugProbeAt' : '``
@@ -449,7 +467,8 @@ X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/
'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/',
+ 'Content-Type' : 'text/plain'
}}
]
}