MCPcopy Create free account
hub / github.com/openclaw/gogcli / ServeHTTP

Method ServeHTTP

internal/gmailwatch/http.go:90–188  ·  view source on GitHub ↗
(response http.ResponseWriter, request *http.Request)

Source from the content-addressed store, hash-verified

88}
89
90func (h *HTTPHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
91 if !PathMatches(h.Config.Path, request.URL.Path) {
92 response.WriteHeader(http.StatusNotFound)
93
94 return
95 }
96
97 if request.Method != http.MethodPost {
98 response.Header().Set("Allow", http.MethodPost)
99 response.WriteHeader(http.StatusMethodNotAllowed)
100
101 return
102 }
103
104 if h.Authorize != nil && !h.Authorize(request) {
105 response.WriteHeader(http.StatusUnauthorized)
106
107 return
108 }
109
110 envelope, err := ParsePush(request, h.Config.BodyLimit)
111 if err != nil {
112 h.warnf("watch: invalid push payload: %v", err)
113 response.WriteHeader(http.StatusBadRequest)
114
115 return
116 }
117
118 payload, err := DecodePushPayload(envelope)
119 if err != nil {
120 h.warnf("watch: invalid push data: %v", err)
121 response.WriteHeader(http.StatusBadRequest)
122
123 return
124 }
125
126 if payload.EmailAddress != "" && !strings.EqualFold(payload.EmailAddress, h.Config.Account) {
127 h.warnf("watch: ignoring push for %s", payload.EmailAddress)
128 response.WriteHeader(http.StatusAccepted)
129
130 return
131 }
132
133 if h.Process == nil {
134 h.warnf("watch: handle push failed: missing processor")
135 response.WriteHeader(http.StatusInternalServerError)
136
137 return
138 }
139
140 processed, err := h.Process(request.Context(), Notification{
141 HistoryID: payload.HistoryID,
142 MessageID: payload.MessageID,
143 })
144 if err != nil {
145 if errors.Is(err, ErrNoNewMessages) {
146 response.WriteHeader(http.StatusAccepted)
147

Calls 9

warnfMethod · 0.95
currentTimeMethod · 0.95
PathMatchesFunction · 0.85
ParsePushFunction · 0.85
DecodePushPayloadFunction · 0.85
RetryAfterSecondsFunction · 0.85
AuthorizeMethod · 0.80
ProcessMethod · 0.80
SetMethod · 0.45