| 474 | } |
| 475 | |
| 476 | func acceptsStreamableHTTP(accept string) bool { |
| 477 | if accept == "" { |
| 478 | return false |
| 479 | } |
| 480 | hasJSON := false |
| 481 | hasSSE := false |
| 482 | for part := range strings.SplitSeq(accept, ",") { |
| 483 | mediaType, params, err := mime.ParseMediaType(strings.TrimSpace(part)) |
| 484 | if err != nil { |
| 485 | continue |
| 486 | } |
| 487 | if q, ok := params["q"]; ok { |
| 488 | quality, err := strconv.ParseFloat(q, 64) |
| 489 | if err == nil && quality == 0 { |
| 490 | continue |
| 491 | } |
| 492 | } |
| 493 | switch mediaType { |
| 494 | case "*/*": |
| 495 | hasJSON = true |
| 496 | hasSSE = true |
| 497 | case "application/*", "application/json": |
| 498 | hasJSON = true |
| 499 | case "text/*", "text/event-stream": |
| 500 | hasSSE = true |
| 501 | } |
| 502 | } |
| 503 | return hasJSON || hasSSE |
| 504 | } |
| 505 | |
| 506 | func validateOrigin(r *http.Request) bool { |
| 507 | origin := r.Header.Get("Origin") |