fix(grpc-gateway): transcode single-value repeated query parameters - #14936
Open
aydinmrnv wants to merge 1 commit into
Open
fix(grpc-gateway): transcode single-value repeated query parameters#14936aydinmrnv wants to merge 1 commit into
aydinmrnv wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
grpc-gatewayplugin returnsHTTP 400 {"message":"failed to encode payload"}when a repeated request field is supplied as a single query-parameter occurrence:?colors=RED(one occurrence)failed to encode payload?colors=RED&colors=BLUE(two occurrences)200?name=bolt200ngx.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. Indeco.lua,add_to_tableassigned that value directly, so a single occurrence handedpb.encodea 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 (
repeatedfor strings/messages/bytes,packedfor numeric/enum/bool) and wraps a single scalar value into a one-element list before encoding, matchinggrpc-ecosystem/grpc-gatewayquery-parameter semantics. Multi-value requests are unchanged.Added a
repeated string tagsfield to the gRPC test fixture and integration tests covering the single-value and multi-value cases.Checklist
changelog/unreleased/kongorskip-changeloglabel added on PR if changelog is unnecessary. README.mdIssue reference
Fix #14907