Skip to content

Commit

Permalink
transformation: fix issue where content-type is removed (#11)
Browse files Browse the repository at this point in the history
* added a failing test
* fix failed test
  • Loading branch information
yuval-k authored and soloio-bulldozer[bot] committed Apr 16, 2019
1 parent 5d4cf2e commit ec7ba42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ void TransformationFilter::transformTemplate(

if (body.length() > 0) {
(this->*addData)(body);
} else {
} else if (!transformation.has_passthrough()) {
// only remove content type if the request is not passthrough.
// This means that the empty body is a result of the transformation.
// so the content type should be removed
header_map.removeContentType();
}
} catch (nlohmann::json::parse_error &e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TransformationFilterTest : public testing::Test {
initFilter(); // Re-load config.
}

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

NiceMock<Http::MockStreamDecoderFilterCallbacks> filter_callbacks_;
Expand Down Expand Up @@ -162,6 +162,24 @@ TEST_F(TransformationFilterTest, HappyPathWithBodyPassthrough) {
EXPECT_EQ(Http::FilterDataStatus::Continue, res);
}


TEST_F(TransformationFilterTest, BodyPassthroughDoesntRemoveContentType) {
auto &transformation = (*route_config_.mutable_request_transformation());
transformation.mutable_transformation_template()->mutable_passthrough();
envoy::api::v2::filter::http::InjaTemplate header_value;
header_value.set_text("added-value");
(*transformation.mutable_transformation_template()->mutable_headers())["added-header"] = header_value;
initFilter(); // Re-load config.

auto resheaders = filter_->decodeHeaders(headers_, false);
EXPECT_EQ(Http::FilterHeadersStatus::Continue, resheaders);

// as this is a passthrough body, transformation should have been triggered
// make sure that transformation did not remove content type.
EXPECT_EQ("test", headers_.get_("content-type"));
EXPECT_EQ("added-value", headers_.get_("added-header"));
}

TEST_F(TransformationFilterTest, HappyPathWithHeadersBodyTemplate) {
initFilterWithHeadersBody();

Expand Down

0 comments on commit ec7ba42

Please sign in to comment.