extractContext reads chat identity headers from the request. Returns zero values if headers are absent (non-chat request).
(r *http.Request)
| 12 | // extractContext reads chat identity headers from the request. |
| 13 | // Returns zero values if headers are absent (non-chat request). |
| 14 | func extractContext(r *http.Request) (chatID uuid.UUID, ancestorIDs []uuid.UUID, ok bool) { |
| 15 | raw := r.Header.Get(workspacesdk.CoderChatIDHeader) |
| 16 | if raw == "" { |
| 17 | return uuid.Nil, nil, false |
| 18 | } |
| 19 | chatID, err := uuid.Parse(raw) |
| 20 | if err != nil { |
| 21 | return uuid.Nil, nil, false |
| 22 | } |
| 23 | rawAncestors := r.Header.Get(workspacesdk.CoderAncestorChatIDsHeader) |
| 24 | if rawAncestors != "" { |
| 25 | var ids []string |
| 26 | if err := json.Unmarshal([]byte(rawAncestors), &ids); err == nil { |
| 27 | for _, s := range ids { |
| 28 | if id, err := uuid.Parse(s); err == nil { |
| 29 | ancestorIDs = append(ancestorIDs, id) |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | return chatID, ancestorIDs, true |
| 35 | } |
no test coverage detected