Skip to content

Commit 646b993

Browse files
yuval-ksoloio-bulldozer[bot]
authored andcommitted
fix handling of no host header (#24)
* fix handling of no host header * use the same route on encode as in decode as if there is no route on decode, there will not be one on encode.
1 parent 90aada7 commit 646b993

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void TransformationFilter::onDestroy() { resetInternalState(); }
2828
Http::FilterHeadersStatus
2929
TransformationFilter::decodeHeaders(Http::HeaderMap &header_map,
3030
bool end_stream) {
31-
3231
checkRequestActive();
3332

3433
if (is_error()) {
@@ -86,7 +85,6 @@ TransformationFilter::decodeTrailers(Http::HeaderMap &) {
8685
Http::FilterHeadersStatus
8786
TransformationFilter::encodeHeaders(Http::HeaderMap &header_map,
8887
bool end_stream) {
89-
9088
checkResponseActive();
9189

9290
if (!responseActive()) {
@@ -142,7 +140,6 @@ void TransformationFilter::checkRequestActive() {
142140
}
143141

144142
void TransformationFilter::checkResponseActive() {
145-
route_ = encoder_callbacks_->route();
146143
response_transformation_ =
147144
getTransformFromRoute(TransformationFilter::Direction::Response);
148145
}

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

+23
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ class TransformationFilterTest : public testing::Test {
3636
perFilterConfig(SoloHttpFilterNames::get().Transformation))
3737
.WillByDefault(Return(route_config_wrapper_.get()));
3838

39+
ON_CALL(encoder_filter_callbacks_, route())
40+
.WillByDefault(Invoke([this]() -> Router::RouteConstSharedPtr {
41+
if (headers_.Host() == nullptr) {
42+
throw std::runtime_error("no host");
43+
}
44+
return encoder_filter_callbacks_.route_;
45+
}));
46+
3947
filter_ = std::make_unique<TransformationFilter>();
4048
filter_->setDecoderFilterCallbacks(filter_callbacks_);
4149
filter_->setEncoderFilterCallbacks(encoder_filter_callbacks_);
@@ -116,6 +124,21 @@ TEST_F(TransformationFilterTest, TransformsResponseOnHeaders) {
116124
EXPECT_EQ(Http::FilterHeadersStatus::Continue, res);
117125
}
118126

127+
TEST_F(TransformationFilterTest, TransformsResponseOnHeadersNoHost) {
128+
headers_.remove(":authority");
129+
route_config_.mutable_response_transformation()
130+
->mutable_transformation_template()
131+
->mutable_body()
132+
->set_text("solo");
133+
134+
initFilter();
135+
136+
// no encode headers to simulate local reply error.
137+
EXPECT_CALL(encoder_filter_callbacks_, addEncodedData(_, false)).Times(0);
138+
auto res = filter_->encodeHeaders(headers_, true);
139+
EXPECT_EQ(Http::FilterHeadersStatus::Continue, res);
140+
}
141+
119142
TEST_F(TransformationFilterTest, ErrorOnBadTemplate) {
120143
initFilterWithBodyTemplate("{{nonexistentvar}}");
121144

0 commit comments

Comments
 (0)