| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package prpc | 5 package prpc |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/base64" | 9 "encoding/base64" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 case formatBinary, formatJSONPB, formatText: | 57 case formatBinary, formatJSONPB, formatText: |
| 58 return f, nil | 58 return f, nil |
| 59 | 59 |
| 60 default: | 60 default: |
| 61 panic("cannot happen") | 61 panic("cannot happen") |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 // readMessage decodes a protobuf message from an HTTP request. | 65 // readMessage decodes a protobuf message from an HTTP request. |
| 66 // Does not close the request body. | 66 // Does not close the request body. |
| 67 func readMessage(r *http.Request, msg proto.Message) *httpError { | 67 func readMessage(r *http.Request, msg proto.Message) *protocolError { |
| 68 if msg == nil { | 68 if msg == nil { |
| 69 panicf("cannot decode to nil") | 69 panicf("cannot decode to nil") |
| 70 } | 70 } |
| 71 format, err := requestFormat(r.Header.Get(headerContentType)) | 71 format, err := requestFormat(r.Header.Get(headerContentType)) |
| 72 if err != nil { | 72 if err != nil { |
| 73 // Spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#
sec10.4.16 | 73 // Spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#
sec10.4.16 |
| 74 return errorf(http.StatusUnsupportedMediaType, "Content-Type hea
der: %s", err) | 74 return errorf(http.StatusUnsupportedMediaType, "Content-Type hea
der: %s", err) |
| 75 } | 75 } |
| 76 | 76 |
| 77 buf, err := ioutil.ReadAll(r.Body) | 77 buf, err := ioutil.ReadAll(r.Body) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 157 } |
| 158 md[trimmedName] = append(md[trimmedName], string
(decoded)) | 158 md[trimmedName] = append(md[trimmedName], string
(decoded)) |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 } | 161 } |
| 162 if addedMeta { | 162 if addedMeta { |
| 163 c = metadata.NewContext(c, md) | 163 c = metadata.NewContext(c, md) |
| 164 } | 164 } |
| 165 return c, nil | 165 return c, nil |
| 166 } | 166 } |
| OLD | NEW |