@@ -880,6 +880,18 @@ TEST(SubstitutionFormatterTest, streamInfoFormatter) {
880880 ProtoEq (ValueUtil::stringValue (" 127.0.0.2:0" )));
881881 }
882882
883+ {
884+ StreamInfoFormatter format (" DOWNSTREAM_DIRECT_LOCAL_ADDRESS" );
885+ auto address = Network::Address::InstanceConstSharedPtr{new Network::Address::Ipv4Instance (
886+ " 127.1.2.3" , 6745 )},
887+ original_address = stream_info.downstream_connection_info_provider_ ->localAddress ();
888+ stream_info.downstream_connection_info_provider_ ->setLocalAddress (address);
889+ EXPECT_EQ (" 127.0.0.2:0" , format.formatWithContext ({}, stream_info));
890+ EXPECT_THAT (format.formatValueWithContext ({}, stream_info),
891+ ProtoEq (ValueUtil::stringValue (" 127.0.0.2:0" )));
892+ stream_info.downstream_connection_info_provider_ ->setLocalAddress (original_address);
893+ }
894+
883895 {
884896 StreamInfoFormatter upstream_format (" DOWNSTREAM_LOCAL_ADDRESS_WITHOUT_PORT" );
885897 EXPECT_EQ (" 127.0.0.2" ,
@@ -891,8 +903,33 @@ TEST(SubstitutionFormatterTest, streamInfoFormatter) {
891903 }
892904
893905 {
894- StreamInfoFormatter upstream_format (" DOWNSTREAM_LOCAL_PORT" );
906+ StreamInfoFormatter format (" DOWNSTREAM_DIRECT_LOCAL_ADDRESS_WITHOUT_PORT" );
907+ EXPECT_EQ (" 127.0.0.2" , format.formatWithContext ({}, stream_info));
908+ EXPECT_THAT (format.formatValueWithContext ({}, stream_info),
909+ ProtoEq (ValueUtil::stringValue (" 127.0.0.2" )));
910+ }
895911
912+ {
913+ StreamInfoFormatter format (" DOWNSTREAM_DIRECT_LOCAL_ADDRESS_WITHOUT_PORT" );
914+ auto address = Network::Address::InstanceConstSharedPtr{
915+ new Network::Address::Ipv4Instance (" 127.1.2.3" , 8900 )};
916+ stream_info.downstream_connection_info_provider_ ->setLocalAddress (address);
917+ EXPECT_EQ (" 127.0.0.2" , format.formatWithContext ({}, stream_info));
918+ EXPECT_THAT (format.formatValueWithContext ({}, stream_info),
919+ ProtoEq (ValueUtil::stringValue (" 127.0.0.2" )));
920+ }
921+
922+ {
923+ StreamInfoFormatter format (" DOWNSTREAM_DIRECT_LOCAL_PORT" );
924+ EXPECT_EQ (" 0" , format.formatWithContext ({}, stream_info));
925+ EXPECT_THAT (format.formatValueWithContext ({}, stream_info), ProtoEq (ValueUtil::numberValue (0 )));
926+ }
927+
928+ {
929+ StreamInfoFormatter downstream_local_port_format (" DOWNSTREAM_LOCAL_PORT" ),
930+ downstream_direct_downstream_local_port_format (" DOWNSTREAM_DIRECT_LOCAL_PORT" );
931+
932+ StreamInfoFormatter upstream_format (" DOWNSTREAM_LOCAL_PORT" );
896933 // Validate for IPv4 address
897934 auto address = Network::Address::InstanceConstSharedPtr{
898935 new Network::Address::Ipv4Instance (" 127.1.2.3" , 8443 )};
@@ -942,6 +979,11 @@ TEST(SubstitutionFormatterTest, streamInfoFormatter) {
942979 EXPECT_THAT (upstream_format.formatValue (request_headers, response_headers, response_trailers,
943980 stream_info, body, AccessLog::AccessLogType::NotSet),
944981 ProtoEq (ValueUtil::nullValue ()));
982+ EXPECT_EQ (" 0" ,
983+ downstream_direct_downstream_local_port_format.formatWithContext ({}, stream_info));
984+ EXPECT_THAT (
985+ downstream_direct_downstream_local_port_format.formatValueWithContext ({}, stream_info),
986+ ProtoEq (ValueUtil::numberValue (0 )));
945987 }
946988
947989 {
0 commit comments