MCPcopy Create free account
hub / github.com/buggregator/server / detectEventType

Function detectEventType

internal/server/http/detect.go:21–65  ·  view source on GitHub ↗

detectEventType extracts event type and project from the request using three methods (matching PHP's DetectEventTypeMiddleware): 1. URI userinfo: http://type@host or http://type:project@host 2. Headers: X-Buggregator-Event / X-Buggregator-Project 3. Basic Auth: Authorization: Basic base64(type:proj

(r *http.Request)

Source from the content-addressed store, hash-verified

19// 2. Headers: X-Buggregator-Event / X-Buggregator-Project
20// 3. Basic Auth: Authorization: Basic base64(type:project)
21func detectEventType(r *http.Request) *DetectedEvent {
22 // Method 1: URI userinfo (e.g., http://sentry@host, http://profiler@host:8000)
23 if r.URL.User != nil {
24 username := r.URL.User.Username()
25 password, _ := r.URL.User.Password()
26 if username != "" {
27 return &DetectedEvent{Type: username, Project: password}
28 }
29 }
30
31 // Method 2: X-Buggregator-Event header
32 if eventType := r.Header.Get("X-Buggregator-Event"); eventType != "" {
33 return &DetectedEvent{
34 Type: eventType,
35 Project: r.Header.Get("X-Buggregator-Project"),
36 }
37 }
38
39 // Method 3: SDK-specific headers that identify the event type.
40 path := strings.TrimRight(r.URL.Path, "/")
41 isSentryStore := strings.HasSuffix(path, "/store") && !strings.Contains(path, "/profiler/")
42 if r.Header.Get("X-Sentry-Auth") != "" || strings.HasSuffix(path, "/envelope") || isSentryStore {
43 return &DetectedEvent{Type: "sentry"}
44 }
45 if r.Header.Get("X-Inspector-Key") != "" || r.Header.Get("X-Inspector-Version") != "" {
46 return &DetectedEvent{Type: "inspector"}
47 }
48
49 // Method 4: Basic Auth (Authorization: Basic base64(type:project))
50 if auth := r.Header.Get("Authorization"); strings.HasPrefix(auth, "Basic ") {
51 decoded, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(auth, "Basic "))
52 if err == nil {
53 parts := strings.SplitN(string(decoded), ":", 2)
54 if len(parts) >= 1 && parts[0] != "" {
55 project := ""
56 if len(parts) >= 2 {
57 project = parts[1]
58 }
59 return &DetectedEvent{Type: parts[0], Project: project}
60 }
61 }
62 }
63
64 return nil
65}

Callers 2

TestDetectEventTypeFunction · 0.85
ServeHTTPMethod · 0.85

Calls 1

GetMethod · 0.45

Tested by 1

TestDetectEventTypeFunction · 0.68