@@ -403,9 +403,8 @@ TEST_P(DynamicModuleHttpFilterHeaderTest, GetHeaders) {
403403}
404404
405405TEST_F (DynamicModuleHttpFilterTest, SendResponseNullptr) {
406- EXPECT_CALL (decoder_callbacks_,
407- sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" " ), _, testing::Eq (absl::nullopt ),
408- testing::Eq (" dynamic_module" )));
406+ EXPECT_CALL (decoder_callbacks_, sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" " ), _,
407+ testing::Eq (0 ), testing::Eq (" dynamic_module" )));
409408 envoy_dynamic_module_callback_http_send_response (filter_.get (), 200 , nullptr , 0 , {nullptr , 0 },
410409 {nullptr , 0 });
411410}
@@ -416,9 +415,8 @@ TEST_F(DynamicModuleHttpFilterTest, SendResponseEmptyResponse) {
416415 .WillRepeatedly (testing::Return (makeOptRef<ResponseHeaderMap>(response_headers)));
417416
418417 // Test with empty response.
419- EXPECT_CALL (decoder_callbacks_,
420- sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" " ), _, testing::Eq (absl::nullopt ),
421- testing::Eq (" dynamic_module" )));
418+ EXPECT_CALL (decoder_callbacks_, sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" " ), _,
419+ testing::Eq (0 ), testing::Eq (" dynamic_module" )));
422420 EXPECT_CALL (decoder_callbacks_, encodeHeaders_ (_, _));
423421
424422 envoy_dynamic_module_callback_http_send_response (filter_.get (), 200 , nullptr , 0 , {nullptr , 0 },
@@ -440,9 +438,8 @@ TEST_F(DynamicModuleHttpFilterTest, SendResponse) {
440438 header_array[index].value_ptr = const_cast <char *>(value.c_str ());
441439 ++index;
442440 }
443- EXPECT_CALL (decoder_callbacks_,
444- sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" " ), _, testing::Eq (absl::nullopt ),
445- testing::Eq (" dynamic_module" )));
441+ EXPECT_CALL (decoder_callbacks_, sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" " ), _,
442+ testing::Eq (0 ), testing::Eq (" dynamic_module" )));
446443 EXPECT_CALL (decoder_callbacks_, encodeHeaders_ (_, _)).WillOnce (Invoke ([](auto & headers, auto ) {
447444 EXPECT_EQ (headers.get (Http::LowerCaseString (" single" ))[0 ]->value ().getStringView (), " value" );
448445 EXPECT_EQ (headers.get (Http::LowerCaseString (" multi" ))[0 ]->value ().getStringView (), " value1" );
@@ -470,9 +467,8 @@ TEST_F(DynamicModuleHttpFilterTest, SendResponseWithBody) {
470467 }
471468
472469 const std::string body_str = " body" ;
473- EXPECT_CALL (decoder_callbacks_,
474- sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" body" ), _,
475- testing::Eq (absl::nullopt ), testing::Eq (" dynamic_module" )));
470+ EXPECT_CALL (decoder_callbacks_, sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" body" ), _,
471+ testing::Eq (0 ), testing::Eq (" dynamic_module" )));
476472 EXPECT_CALL (decoder_callbacks_, encodeHeaders_ (_, _)).WillOnce (Invoke ([](auto & headers, auto ) {
477473 EXPECT_EQ (headers.get (Http::LowerCaseString (" single" ))[0 ]->value ().getStringView (), " value" );
478474 EXPECT_EQ (headers.get (Http::LowerCaseString (" multi" ))[0 ]->value ().getStringView (), " value1" );
@@ -485,41 +481,13 @@ TEST_F(DynamicModuleHttpFilterTest, SendResponseWithBody) {
485481TEST_F (DynamicModuleHttpFilterTest, SendResponseWithCustomResponseCodeDetails) {
486482 const std::string body_str = " body" ;
487483 absl::string_view test_details = " test_details" ;
488- EXPECT_CALL (decoder_callbacks_,
489- sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" body" ), _,
490- testing::Eq (absl::nullopt ), testing::Eq (" test_details" )));
484+ EXPECT_CALL (decoder_callbacks_, sendLocalReply (Envoy::Http::Code::OK, testing::Eq (" body" ), _,
485+ testing::Eq (0 ), testing::Eq (" test_details" )));
491486 envoy_dynamic_module_callback_http_send_response (filter_.get (), 200 , nullptr , 0 ,
492487 {body_str.data (), body_str.size ()},
493488 {test_details.data (), test_details.size ()});
494489}
495490
496- TEST_F (DynamicModuleHttpFilterTest, SendResponseWithGrpcStatusHeader) {
497- // Verify that grpc-status passed as a header is forwarded via modify_headers.
498- std::string grpc_status_key = " grpc-status" ;
499- std::string grpc_status_value = " 14" ;
500- envoy_dynamic_module_type_module_http_header header_array[1 ];
501- header_array[0 ].key_ptr = grpc_status_key.data ();
502- header_array[0 ].key_length = grpc_status_key.size ();
503- header_array[0 ].value_ptr = grpc_status_value.data ();
504- header_array[0 ].value_length = grpc_status_value.size ();
505-
506- EXPECT_CALL (decoder_callbacks_,
507- sendLocalReply (Envoy::Http::Code::ServiceUnavailable, testing::Eq (" " ), _,
508- testing::Eq (absl::nullopt ), testing::Eq (" dynamic_module" )))
509- .WillOnce (Invoke ([](Http::Code, absl::string_view,
510- std::function<void (Http::ResponseHeaderMap & headers)> modify_headers,
511- absl::optional<Grpc::Status::GrpcStatus>, absl::string_view) {
512- Http::TestResponseHeaderMapImpl headers;
513- if (modify_headers) {
514- modify_headers (headers);
515- }
516- EXPECT_EQ (headers.get (Http::LowerCaseString (" grpc-status" ))[0 ]->value ().getStringView (),
517- " 14" );
518- }));
519- envoy_dynamic_module_callback_http_send_response (filter_.get (), 503 , header_array, 1 ,
520- {nullptr , 0 }, {nullptr , 0 });
521- }
522-
523491TEST_F (DynamicModuleHttpFilterTest, AddCustomFlag) {
524492 // Test with empty response.
525493 EXPECT_CALL (decoder_callbacks_.stream_info_ , addCustomFlag (testing::Eq (" XXX" )));
@@ -2016,67 +1984,6 @@ TEST(ABIImpl, GetAttributes) {
20161984 EXPECT_EQ (result_number, 8386 );
20171985}
20181986
2019- TEST (ABIImpl, GetAttributeResponseGrpcStatus) {
2020- Stats::SymbolTableImpl symbol_table;
2021- DynamicModuleHttpFilter filter{nullptr , symbol_table, 0 };
2022- NiceMock<Http::MockStreamDecoderFilterCallbacks> decoder_callbacks;
2023- NiceMock<Http::MockStreamEncoderFilterCallbacks> encoder_callbacks;
2024- StreamInfo::MockStreamInfo stream_info;
2025- EXPECT_CALL (decoder_callbacks, streamInfo ()).WillRepeatedly (testing::ReturnRef (stream_info));
2026- filter.setDecoderFilterCallbacks (decoder_callbacks);
2027- filter.setEncoderFilterCallbacks (encoder_callbacks);
2028-
2029- uint64_t result = 0 ;
2030-
2031- // Without response trailers or headers, gRPC status should be inferred from HTTP response code.
2032- EXPECT_CALL (encoder_callbacks, responseTrailers ())
2033- .WillRepeatedly (testing::Return (ResponseTrailerMapOptRef ()));
2034- EXPECT_CALL (encoder_callbacks, responseHeaders ())
2035- .WillRepeatedly (testing::Return (ResponseHeaderMapOptRef ()));
2036- EXPECT_CALL (stream_info, responseCode ()).WillRepeatedly (testing::Return (503 ));
2037- EXPECT_TRUE (envoy_dynamic_module_callback_http_filter_get_attribute_int (
2038- &filter, envoy_dynamic_module_type_attribute_id_ResponseGrpcStatus, &result));
2039- // HTTP 503 maps to gRPC Unavailable (14).
2040- EXPECT_EQ (result, 14 );
2041- }
2042-
2043- TEST (ABIImpl, GetAttributeResponseGrpcStatusFromTrailers) {
2044- Stats::SymbolTableImpl symbol_table;
2045- DynamicModuleHttpFilter filter{nullptr , symbol_table, 0 };
2046- NiceMock<Http::MockStreamDecoderFilterCallbacks> decoder_callbacks;
2047- NiceMock<Http::MockStreamEncoderFilterCallbacks> encoder_callbacks;
2048- StreamInfo::MockStreamInfo stream_info;
2049- EXPECT_CALL (decoder_callbacks, streamInfo ()).WillRepeatedly (testing::ReturnRef (stream_info));
2050- filter.setDecoderFilterCallbacks (decoder_callbacks);
2051- filter.setEncoderFilterCallbacks (encoder_callbacks);
2052-
2053- uint64_t result = 0 ;
2054-
2055- // With grpc-status in response trailers, that should take precedence.
2056- Http::TestResponseTrailerMapImpl trailers{{" grpc-status" , " 7" }};
2057- EXPECT_CALL (encoder_callbacks, responseTrailers ())
2058- .WillRepeatedly (testing::Return (makeOptRef<ResponseTrailerMap>(trailers)));
2059- EXPECT_CALL (encoder_callbacks, responseHeaders ())
2060- .WillRepeatedly (testing::Return (ResponseHeaderMapOptRef ()));
2061- EXPECT_CALL (stream_info, responseCode ()).WillRepeatedly (testing::Return (200 ));
2062- EXPECT_TRUE (envoy_dynamic_module_callback_http_filter_get_attribute_int (
2063- &filter, envoy_dynamic_module_type_attribute_id_ResponseGrpcStatus, &result));
2064- // grpc-status: 7 = PermissionDenied.
2065- EXPECT_EQ (result, 7 );
2066- }
2067-
2068- TEST (ABIImpl, GetAttributeResponseGrpcStatusNotAvailable) {
2069- Stats::SymbolTableImpl symbol_table;
2070- DynamicModuleHttpFilter filter_without_callbacks{nullptr , symbol_table, 0 };
2071-
2072- uint64_t result = 0 ;
2073-
2074- // Without callbacks, stream info is not available.
2075- EXPECT_FALSE (envoy_dynamic_module_callback_http_filter_get_attribute_int (
2076- &filter_without_callbacks, envoy_dynamic_module_type_attribute_id_ResponseGrpcStatus,
2077- &result));
2078- }
2079-
20801987TEST (ABIImpl, HttpCallout) {
20811988 Stats::SymbolTableImpl symbol_table;
20821989 DynamicModuleHttpFilter filter{nullptr , symbol_table, 0 };
0 commit comments