(_ goHttp.ResponseWriter, request *goHttp.Request)
| 89 | } |
| 90 | |
| 91 | func (h *handler) findMarshaller(_ goHttp.ResponseWriter, request *goHttp.Request) (responseMarshaller, string, int) { |
| 92 | acceptHeader := request.Header.Get("Accept") |
| 93 | if acceptHeader == "" { |
| 94 | return h.defaultResponseMarshaller, h.defaultResponseType, 200 |
| 95 | } |
| 96 | |
| 97 | accepted := strings.Split(acceptHeader, ",") |
| 98 | acceptMap := make(map[string]float64, len(accepted)) |
| 99 | acceptList := make([]string, len(accepted)) |
| 100 | for i, accept := range accepted { |
| 101 | acceptParts := strings.SplitN(strings.TrimSpace(accept), ";", 2) |
| 102 | q := 1.0 |
| 103 | if len(acceptParts) == 2 { |
| 104 | acceptParts2 := strings.SplitN(acceptParts[1], "=", 2) |
| 105 | if acceptParts2[0] == "q" && len(acceptParts2) == 2 { |
| 106 | var err error |
| 107 | q, err = strconv.ParseFloat(acceptParts2[1], 64) |
| 108 | if err != nil { |
| 109 | return nil, h.defaultResponseType, 400 |
| 110 | } |
| 111 | } else { |
| 112 | return nil, h.defaultResponseType, 400 |
| 113 | } |
| 114 | } |
| 115 | acceptMap[acceptParts[0]] = q |
| 116 | acceptList[i] = acceptParts[0] |
| 117 | } |
| 118 | sort.SliceStable(acceptList, func(i, j int) bool { |
| 119 | return acceptMap[acceptList[i]] > acceptMap[acceptList[j]] |
| 120 | }) |
| 121 | |
| 122 | for _, a := range acceptList { |
| 123 | for _, marshaller := range h.responseMarshallers { |
| 124 | if marshaller.SupportsMIME(a) { |
| 125 | return marshaller, a, 200 |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | return nil, h.defaultResponseType, 406 |
| 130 | } |
| 131 | |
| 132 | type internalRequest struct { |
| 133 | writer goHttp.ResponseWriter |
no test coverage detected