test/extensions/filters/http/ext_proc/filter_test.cc
// Using the default configuration, test the filter with a processor that
// replies to the request_headers message with a message that modifies the request
// headers.
Using the default configuration, test the filter with a processor that
replies to the request_headers message with a message that modifies the request
headers.
Using the default configuration test the filter with a processor that replies to the request_headers message with a message that modifies the request headers .
TEST_F(HttpFilterTest, PostAndChangeHeaders) {
  initialize(R"EOF(
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
  )EOF");
  HttpTestUtility::addDefaultHeaders(request_headers_, "POST");
  request_headers_.addCopy(LowerCaseString("x-some-other-header"), "yes");
  request_headers_.addCopy(LowerCaseString("x-do-we-want-this"), "no");
  EXPECT_EQ(FilterHeadersStatus::StopAllIterationAndWatermark,
            filter_->decodeHeaders(request_headers_, false));
  EXPECT_FALSE(last_request_.async_mode());
  EXPECT_FALSE(stream_close_sent_);
  ASSERT_TRUE(last_request_.has_request_headers());
  EXPECT_CALL(decoder_callbacks_, continueDecoding());
  std::unique_ptr<ProcessingResponse> resp1 = std::make_unique<ProcessingResponse>();
  auto req_headers_response = resp1->mutable_request_headers();
  auto headers_mut = req_headers_response->mutable_response()->mutable_header_mutation();
  auto add1 = headers_mut->add_set_headers();
  add1->mutable_header()->set_key("x-new-header");
  add1->mutable_header()->set_value("new");
  add1->mutable_append()->set_value(false);
  auto add2 = headers_mut->add_set_headers();
  add2->mutable_header()->set_key("x-some-other-header");
  add2->mutable_header()->set_value("no");
  add2->mutable_append()->set_value(true);
  *headers_mut->add_remove_headers() = "x-do-we-want-this";
  stream_callbacks_->onReceiveMessage(std::move(resp1));
  Http::TestRequestHeaderMapImpl expected{{":path", "/"},
                                          {":method", "POST"},
                                          {":scheme", "http"},
                                          {"host", "host"},
                                          {"x-new-header", "new"},
                                          {"x-some-other-header", "yes"},
                                          {"x-some-other-header", "no"}};
  EXPECT_TRUE(TestUtility::headerMapEqualIgnoreOrder(expected, request_headers_));
  data_.add("foo");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->decodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->decodeTrailers(request_trailers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encode100ContinueHeaders(response_headers_));
  EXPECT_EQ(FilterHeadersStatus::Continue, filter_->encodeHeaders(response_headers_, true));
  data_.add("bar");
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, false));
  EXPECT_EQ(FilterDataStatus::Continue, filter_->encodeData(data_, true));
  EXPECT_EQ(FilterTrailersStatus::Continue, filter_->encodeTrailers(response_trailers_));
  filter_->onDestroy();
  EXPECT_TRUE(stream_close_sent_);
  EXPECT_EQ(1, config_->stats().streams_started_.value());
  EXPECT_EQ(1, config_->stats().stream_msgs_sent_.value());
  EXPECT_EQ(1, config_->stats().stream_msgs_received_.value());
  EXPECT_EQ(1, config_->stats().streams_closed_.value());
}
TEST_F ( HttpFilterTest , PostAndChangeHeaders ) { initialize ( R" EOF ( 
  grpc_service:
    envoy_grpc:
      cluster_name: "ext_proc_server"
   ) EOF " ) ; HttpTestUtility :: addDefaultHeaders ( request_headers_ , " " ) ; request_headers_ . addCopy ( LowerCaseString ( " " ) , " " ) ; request_headers_ . addCopy ( LowerCaseString ( " " ) , " " ) ; EXPECT_EQ ( FilterHeadersStatus :: StopAllIterationAndWatermark , filter_ -> decodeHeaders ( request_headers_ , false ) ) ; EXPECT_FALSE ( last_request_ . async_mode ( ) ) ; EXPECT_FALSE ( stream_close_sent_ ) ; ASSERT_TRUE ( last_request_ . has_request_headers ( ) ) ; EXPECT_CALL ( decoder_callbacks_ , continueDecoding ( ) ) ; std :: unique_ptr < ProcessingResponse > resp1 = std :: make_unique < ProcessingResponse > ( ) ; auto req_headers_response = resp1 -> mutable_request_headers ( ) ; auto headers_mut = req_headers_response -> mutable_response ( ) -> mutable_header_mutation ( ) ; auto add1 = headers_mut -> add_set_headers ( ) ; add1 -> mutable_header ( ) -> set_key ( " " ) ; add1 -> mutable_header ( ) -> set_value ( " " ) ; add1 -> mutable_append ( ) -> set_value ( false ) ; auto add2 = headers_mut -> add_set_headers ( ) ; add2 -> mutable_header ( ) -> set_key ( " " ) ; add2 -> mutable_header ( ) -> set_value ( " " ) ; add2 -> mutable_append ( ) -> set_value ( true ) ; * headers_mut -> add_remove_headers ( ) = " " ; stream_callbacks_ -> onReceiveMessage ( std :: move ( resp1 ) ) ; Http :: TestRequestHeaderMapImpl expected { { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } , { " " , " " } } ; EXPECT_TRUE ( TestUtility :: headerMapEqualIgnoreOrder ( expected , request_headers_ ) ) ; data_ . add ( " " ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> decodeData ( data_ , true ) ) ; EXPECT_EQ ( FilterTrailersStatus :: Continue , filter_ -> decodeTrailers ( request_trailers_ ) ) ; EXPECT_EQ ( FilterHeadersStatus :: Continue , filter_ -> encode100ContinueHeaders ( response_headers_ ) ) ; EXPECT_EQ ( FilterHeadersStatus :: Continue , filter_ -> encodeHeaders ( response_headers_ , true ) ) ; data_ . add ( " " ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> encodeData ( data_ , false ) ) ; EXPECT_EQ ( FilterDataStatus :: Continue , filter_ -> encodeData ( data_ , true ) ) ; EXPECT_EQ ( FilterTrailersStatus :: Continue , filter_ -> encodeTrailers ( response_trailers_ ) ) ; filter_ -> onDestroy ( ) ; EXPECT_TRUE ( stream_close_sent_ ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . streams_started_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . stream_msgs_sent_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . stream_msgs_received_ . value ( ) ) ; EXPECT_EQ ( 1 , config_ -> stats ( ) . streams_closed_ . value ( ) ) ; }
Using the default configuration, test the filter with a processor that
replies to the request_headers message with a message that modifies the request
headers.
Using the default configuration test the filter with a processor that replies to the request_headers message with a message that modifies the request headers .
// We should now have changed the original header a bit