Skip to content

fix(grpc-gateway): transcode single-value repeated query parameters - #14936

Open
aydinmrnv wants to merge 1 commit into
Kong:masterfrom
aydinmrnv:fix/grpc-gateway-repeated-single-value
Open

fix(grpc-gateway): transcode single-value repeated query parameters#14936
aydinmrnv wants to merge 1 commit into
Kong:masterfrom
aydinmrnv:fix/grpc-gateway-repeated-single-value

Conversation

@aydinmrnv

Copy link
Copy Markdown

Summary

The grpc-gateway plugin returns HTTP 400 {"message":"failed to encode payload"} when a repeated request field is supplied as a single query-parameter occurrence:

Request Before
?colors=RED (one occurrence) 400 failed to encode payload
?colors=RED&colors=BLUE (two occurrences) 200
scalar field ?name=bolt 200

ngx.req.get_uri_args() returns a bare string when a parameter occurs once and a Lua table only when it occurs two or more times. In deco.lua, add_to_table assigned that value directly, so a single occurrence handed pb.encode a scalar where a repeated field requires a list — hence the encode failure. Two-or-more occurrences already produced a table and worked. The single-value case is the common one (one selected filter).

This PR detects repeated fields from the protobuf field label (repeated for strings/messages/bytes, packed for numeric/enum/bool) and wraps a single scalar value into a one-element list before encoding, matching grpc-ecosystem/grpc-gateway query-parameter semantics. Multi-value requests are unchanged.

Added a repeated string tags field to the gRPC test fixture and integration tests covering the single-value and multi-value cases.

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/developer.konghq.com - PUT DOCS PR HERE

Issue reference

Fix #14907

get_uri_args returns a bare string for a query parameter that appears
once and a table only when it appears two or more times. For a repeated
proto field that meant a single occurrence (?colors=RED) was handed to
pb.encode as a scalar, which failed with 'failed to encode payload',
while two or more occurrences worked.

Detect repeated fields from the field label (repeated/packed) and wrap a
single scalar value into a one-element list before encoding.

Fixes Kong#14907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

grpc-gateway: repeated field as a single query parameter fails to transcode (400 "failed to encode payload")

1 participant