Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Don't URL-encode slashes in gRPC request headers. #6310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api_core/google/api_core/gapic_v1/routing_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Generally, these headers are specified as gRPC metadata.
"""

import sys

from six.moves.urllib.parse import urlencode

ROUTING_METADATA_KEY = 'x-goog-request-params'
Expand All @@ -35,7 +37,13 @@ def to_routing_header(params):
Returns:
str: The routing header string.
"""
return urlencode(params)
if sys.version_info[0] < 3:
# Python 2 does not have the "safe" parameter for urlencode.
return urlencode(params).replace('%2F', '/')
return urlencode(
params,
# Per Google API policy (go/api-url-encoding), / is not encoded.
safe='/')


def to_grpc_metadata(params):
Expand Down
6 changes: 6 additions & 0 deletions api_core/tests/unit/gapic/test_routing_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def test_to_routing_header():
assert value == "name=meep&book.read=1"


def test_to_routing_header_with_slashes():
params = [('name', 'me/ep'), ('book.read', '1&2')]
value = routing_header.to_routing_header(params)
assert value == "name=me/ep&book.read=1%262"


def test_to_grpc_metadata():
params = [('name', 'meep'), ('book.read', '1')]
metadata = routing_header.to_grpc_metadata(params)
Expand Down