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

Unified Diff: server/prpc/decoding.go

Issue 1636873006: server/prpc: updated server according to protocol (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Removed some panics, malformed JSON now errors. Created 4 years, 11 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
Index: server/prpc/decoding.go
diff --git a/server/prpc/decoding.go b/server/prpc/decoding.go
index 874c48111b51c9267d89e6f4e071dadad013fb61..a6ae48875be64d3054ac16146ab3ffff67b8ef32 100644
--- a/server/prpc/decoding.go
+++ b/server/prpc/decoding.go
@@ -51,23 +51,17 @@ func requestFormat(contentType string) (format, error) {
case formatUnrecognized:
return f, fmt.Errorf("%q is not supported", contentType)
- case formatUnspecified:
- return formatBinary, nil
-
case formatBinary, formatJSONPB, formatText:
return f, nil
default:
- panic("cannot happen")
+ return formatBinary, nil
}
}
// readMessage decodes a protobuf message from an HTTP request.
// Does not close the request body.
-func readMessage(r *http.Request, msg proto.Message) *httpError {
- if msg == nil {
- panicf("cannot decode to nil")
- }
+func readMessage(r *http.Request, msg proto.Message) *protocolError {
format, err := requestFormat(r.Header.Get(headerContentType))
if err != nil {
// Spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.16
@@ -78,11 +72,6 @@ func readMessage(r *http.Request, msg proto.Message) *httpError {
if err != nil {
return errorf(http.StatusBadRequest, "could not read body: %s", err)
}
- if len(buf) == 0 {
- // no body, no message
- return nil
- }
-
switch format {
// Do not redefine "err" below.
@@ -96,7 +85,7 @@ func readMessage(r *http.Request, msg proto.Message) *httpError {
err = proto.UnmarshalText(string(buf), msg)
default:
- panicf("cannot happen")
+ err = fmt.Errorf("unknown message format: %d", format)
}
if err != nil {
return errorf(http.StatusBadRequest, "could not decode body: %s", err)
« no previous file with comments | « server/prpc/auth.go ('k') | server/prpc/decoding_test.go » ('j') | server/prpc/encoding.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698