Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: appengine/components/components/endpoints_webapp2.py

Issue 2370413002: endpoints_webapp2: honor GET requests with messages (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: nit Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | appengine/components/components/endpoints_webapp2_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/components/components/endpoints_webapp2.py
diff --git a/appengine/components/components/endpoints_webapp2.py b/appengine/components/components/endpoints_webapp2.py
index 5bac568e736c137210e966ac4f57e98159be99d7..8b619dc1819ad4a823b291dd5d2bdf20c212f2d4 100644
--- a/appengine/components/components/endpoints_webapp2.py
+++ b/appengine/components/components/endpoints_webapp2.py
@@ -50,26 +50,34 @@ def decode_message(remote_method_info, request):
body_type = remote_method_info.request_type
body = PROTOCOL.decode_message(body_type, request.body)
- if not res_container:
- return body
-
- msg = res_container.combined_message_class()
- for f in body.all_fields():
- setattr(msg, f.name, getattr(body, f.name))
-
- # We expect fields in the resource container to be in the URL.
- for f in res_container.parameters_message_class.all_fields():
- if f.name in request.route_kwargs:
- values = [request.route_kwargs[f.name]]
+ if res_container:
+ result = res_container.combined_message_class()
+ for f in body.all_fields():
+ setattr(result, f.name, getattr(body, f.name))
+ else:
+ result = body
+
+ # Read field values from query string parameters or URL path.
+ if res_container or request.method == 'GET':
+ # In addition to standard ResourceContainer request type, we also support
+ # GET request handlers that use Message instead of ResourceContainer,
+ # because it is non-ambiguous (because GET requests cannot have body).
+ if res_container:
+ param_fields = res_container.parameters_message_class.all_fields()
else:
- values = request.get_all(f.name)
- if values:
- values = [decode_field(f, v) for v in values]
- if f.repeated:
- getattr(msg, f.name).extend(values)
+ param_fields = result.all_fields()
+ for f in param_fields:
+ if f.name in request.route_kwargs:
+ values = [request.route_kwargs[f.name]]
else:
- setattr(msg, f.name, values[0])
- return msg
+ values = request.get_all(f.name)
+ if values:
+ values = [decode_field(f, v) for v in values]
+ if f.repeated:
+ getattr(result, f.name).extend(values)
+ else:
+ setattr(result, f.name, values[0])
+ return result
def add_cors_headers(headers):
« no previous file with comments | « no previous file | appengine/components/components/endpoints_webapp2_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698