MatchWithError returns true if r matches m.
(r *http.Request)
| 1257 | |
| 1258 | // MatchWithError returns true if r matches m. |
| 1259 | func (m MatchProtocol) MatchWithError(r *http.Request) (bool, error) { |
| 1260 | switch string(m) { |
| 1261 | case "grpc": |
| 1262 | return strings.HasPrefix(r.Header.Get("content-type"), "application/grpc"), nil |
| 1263 | case "https": |
| 1264 | return r.TLS != nil, nil |
| 1265 | case "http": |
| 1266 | return r.TLS == nil, nil |
| 1267 | case "http/1.0": |
| 1268 | return r.ProtoMajor == 1 && r.ProtoMinor == 0, nil |
| 1269 | case "http/1.0+": |
| 1270 | return r.ProtoAtLeast(1, 0), nil |
| 1271 | case "http/1.1": |
| 1272 | return r.ProtoMajor == 1 && r.ProtoMinor == 1, nil |
| 1273 | case "http/1.1+": |
| 1274 | return r.ProtoAtLeast(1, 1), nil |
| 1275 | case "http/2": |
| 1276 | return r.ProtoMajor == 2, nil |
| 1277 | case "http/2+": |
| 1278 | return r.ProtoAtLeast(2, 0), nil |
| 1279 | case "http/3": |
| 1280 | return r.ProtoMajor == 3, nil |
| 1281 | case "http/3+": |
| 1282 | return r.ProtoAtLeast(3, 0), nil |
| 1283 | } |
| 1284 | return false, nil |
| 1285 | } |
| 1286 | |
| 1287 | // UnmarshalCaddyfile implements caddyfile.Unmarshaler. |
| 1288 | func (m *MatchProtocol) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { |