MarshalerForRequest returns the inbound/outbound marshalers for this request. It checks the registry on the ServeMux for the MIME type set by the Content-Type header. If it isn't set (or the request Content-Type is empty), checks for "*". If there are multiple Content-Type headers set, choose the fi
(mux *ServeMux, r *http.Request)
| 36 | // exactly match in the registry. |
| 37 | // Otherwise, it follows the above logic for "*"/InboundMarshaler/OutboundMarshaler. |
| 38 | func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler) { |
| 39 | for _, acceptVal := range r.Header[acceptHeader] { |
| 40 | if m, ok := mux.marshalers.mimeMap[acceptVal]; ok { |
| 41 | outbound = m |
| 42 | break |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | for _, contentTypeVal := range r.Header[contentTypeHeader] { |
| 47 | contentType, _, err := mime.ParseMediaType(contentTypeVal) |
| 48 | if err != nil { |
| 49 | grpclog.Errorf("Failed to parse Content-Type %s: %v", contentTypeVal, err) |
| 50 | continue |
| 51 | } |
| 52 | if m, ok := mux.marshalers.mimeMap[contentType]; ok { |
| 53 | inbound = m |
| 54 | break |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if inbound == nil { |
| 59 | inbound = mux.marshalers.mimeMap[MIMEWildcard] |
| 60 | } |
| 61 | if outbound == nil { |
| 62 | outbound = inbound |
| 63 | } |
| 64 | |
| 65 | return inbound, outbound |
| 66 | } |
| 67 | |
| 68 | // marshalerRegistry is a mapping from MIME types to Marshalers. |
| 69 | type marshalerRegistry struct { |
no outgoing calls