Skip to content

Commit ec7ba42

Browse files
yuval-ksoloio-bulldozer[bot]
authored andcommitted
transformation: fix issue where content-type is removed (#11)
* added a failing test * fix failed test
1 parent 5d4cf2e commit ec7ba42

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

source/extensions/filters/http/transformation/transformation_filter.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,10 @@ void TransformationFilter::transformTemplate(
226226

227227
if (body.length() > 0) {
228228
(this->*addData)(body);
229-
} else {
229+
} else if (!transformation.has_passthrough()) {
230+
// only remove content type if the request is not passthrough.
231+
// This means that the empty body is a result of the transformation.
232+
// so the content type should be removed
230233
header_map.removeContentType();
231234
}
232235
} catch (nlohmann::json::parse_error &e) {

test/extensions/filters/http/transformation/transformation_filter_test.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TransformationFilterTest : public testing::Test {
6363
initFilter(); // Re-load config.
6464
}
6565

66-
Http::TestHeaderMapImpl headers_{
66+
Http::TestHeaderMapImpl headers_{{"content-type", "test"},
6767
{":method", "GET"}, {":authority", "www.solo.io"}, {":path", "/path"}};
6868

6969
NiceMock<Http::MockStreamDecoderFilterCallbacks> filter_callbacks_;
@@ -162,6 +162,24 @@ TEST_F(TransformationFilterTest, HappyPathWithBodyPassthrough) {
162162
EXPECT_EQ(Http::FilterDataStatus::Continue, res);
163163
}
164164

165+
166+
TEST_F(TransformationFilterTest, BodyPassthroughDoesntRemoveContentType) {
167+
auto &transformation = (*route_config_.mutable_request_transformation());
168+
transformation.mutable_transformation_template()->mutable_passthrough();
169+
envoy::api::v2::filter::http::InjaTemplate header_value;
170+
header_value.set_text("added-value");
171+
(*transformation.mutable_transformation_template()->mutable_headers())["added-header"] = header_value;
172+
initFilter(); // Re-load config.
173+
174+
auto resheaders = filter_->decodeHeaders(headers_, false);
175+
EXPECT_EQ(Http::FilterHeadersStatus::Continue, resheaders);
176+
177+
// as this is a passthrough body, transformation should have been triggered
178+
// make sure that transformation did not remove content type.
179+
EXPECT_EQ("test", headers_.get_("content-type"));
180+
EXPECT_EQ("added-value", headers_.get_("added-header"));
181+
}
182+
165183
TEST_F(TransformationFilterTest, HappyPathWithHeadersBodyTemplate) {
166184
initFilterWithHeadersBody();
167185

0 commit comments

Comments
 (0)