nic-6443 commented on code in PR #13499:
URL: https://github.com/apache/apisix/pull/13499#discussion_r3385507619
##########
t/plugin/proxy-mirror3.t:
##########
@@ -68,9 +89,40 @@ routes:
#END
--- exec
grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
+sleep 0.5
--- response_body
{
"message": "Hello apisix"
}
---- error_log eval
-qr/Connection refused\) while connecting to upstream/
+--- error_log
+grpc mirror server got request: path=/helloworld.Greeter/SayHello
content_type=application/grpc body_len=13
+
Review Comment:
The 13-byte length is deterministic, not version-dependent: it is the 5-byte
gRPC frame prefix (no compression flag + 4-byte length) plus the 8-byte
protobuf message (field 1, wire type 2, length 6, "apisix"). grpcurl does not
compress by default, and the grpc-web case sends those exact bytes via curl.
The exact length assertion is intentional — it verifies the mirrored body is
byte-identical to the main request body, so a regression that truncates or
duplicates the mirrored body would be caught. Loosening it to any numeric value
would silently pass such regressions, so I will keep it as is.
##########
t/plugin/proxy-mirror3.t:
##########
@@ -68,9 +89,40 @@ routes:
#END
--- exec
grpcurl -import-path ./t/grpc_server_example/proto -proto helloworld.proto
-plaintext -d '{"name":"apisix"}' 127.0.0.1:1984 helloworld.Greeter.SayHello
+sleep 0.5
--- response_body
{
"message": "Hello apisix"
}
---- error_log eval
-qr/Connection refused\) while connecting to upstream/
+--- error_log
+grpc mirror server got request: path=/helloworld.Greeter/SayHello
content_type=application/grpc body_len=13
+
+
+
+=== TEST 2: grpc mirror keeps the URI rewritten by access phase plugins
(grpc-web)
+--- apisix_yaml
+routes:
+ -
+ id: 1
+ uris:
+ - /grpc/web/*
+ plugins:
+ grpc-web: {}
+ proxy-mirror:
+ host: grpc://127.0.0.1:19797
+ sample_ratio: 1
+ upstream:
+ scheme: grpc
+ nodes:
+ "127.0.0.1:10051": 1
+ type: roundrobin
+#END
+--- exec
+printf '\000\000\000\000\010\012\006apisix' | curl -s -o /dev/null -w
"code=%{http_code}" -X POST \
+ -H 'Content-Type: application/grpc-web+proto' --data-binary @- \
+ http://127.0.0.1:1984/grpc/web/helloworld.Greeter/SayHello
+sleep 0.5
+--- response_body chomp
+code=200
+--- error_log
+grpc mirror server got request: path=/helloworld.Greeter/SayHello
content_type=application/grpc body_len=13
Review Comment:
The 13-byte length is deterministic, not version-dependent: it is the 5-byte
gRPC frame prefix (no compression flag + 4-byte length) plus the 8-byte
protobuf message (field 1, wire type 2, length 6, "apisix"). grpcurl does not
compress by default, and the grpc-web case sends those exact bytes via curl.
The exact length assertion is intentional — it verifies the mirrored body is
byte-identical to the main request body, so a regression that truncates or
duplicates the mirrored body would be caught. Loosening it to any numeric value
would silently pass such regressions, so I will keep it as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]